Access: Delete all records in a Table
Results 1 to 2 of 2

Thread: Access: Delete all records in a Table

  1. #1
    Board Regular gheyman's Avatar
    Join Date
    Nov 2005
    Location
    Orlando, FL USA
    Posts
    1,571
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Access: Delete all records in a Table

    I have a situation where I want to delete all records in a table - I don't want to delete the table - just the records.

    Is there a way to do this in VBA (click button event)

    My table name is "ModelGeneral_vluItem1"

    Thanks! I really appreciate the help.
    G Heyman
    Northrop Grumman - Laser Systems'
    Apopka, FL

  2. #2
    MrExcel MVP
    Moderator
    xenou's Avatar
    Join Date
    Mar 2007
    Location
    Clev. OH, USA
    Posts
    16,423
    Post Thanks / Like
    Mentioned
    11 Post(s)
    Tagged
    1 Thread(s)

    Default Re: Access: Delete all records in a Table

    Running a delete query in the button code is a simple option:

    Either:
    Code:
    Sub Foo()
    
        DoCmd.SetWarnings False
        DoCmd.RunSQL "delete * From [Table2];"
        DoCmd.SetWarnings True
    
    End Sub
    Or:
    Code:
    Sub Bar()
    
    On Error GoTo ErrHandler:
    CurrentDb.Execute "delete * From [Table2];", dbFailOnError
    
    MyExit:
        Exit Sub
    
    ErrHandler:
    MsgBox "An error occurred."
    
    End Sub

    I usually use the former because I maintain and use my own databases so the chances of error are very low (meaning, I've never had a problem deleting rows from a table). The latter might be better if you require absolute certainty about the reliability of the code or have other users that are working with the database.

    Using: Office 2010/Win7 (work) Office 2010/Win7 (home)

    You are rich in proportion to the number of things you can let alone.
    -- Henry David Thoreau

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •