Access: Delete all records in a Table

gheyman

Well-known Member
Joined
Nov 14, 2005
Messages
1,730
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.
 

Some videos you may like

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.

xenou

MrExcel MVP, Moderator
Joined
Mar 2, 2007
Messages
16,645
Office Version
2013
Platform
Windows
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,099,258
Messages
5,467,616
Members
406,545
Latest member
puneet829

This Week's Hot Topics

Top