Code to delete records in a Table (1 Viewer)

wan2fly99

Registered User.
Local time
Today, 08:30
Joined
Feb 7, 2005
Messages
53
Can somebody point me in the right direction
for some VBA code to delete all records
in a table. I know I can create a macro and call the macro,
but like to do it in VBA

Thanks for any help
 

daveUK

Registered User.
Local time
Today, 16:30
Joined
Jan 2, 2002
Messages
234
If you want to delete ALL the records use the following

Code:
Docmd.RunSQL "DELETE * FROM NameOfTable"

If you want to supress the warning message use

Code:
DoCmd.SetWarnings False
DoCmd.RunSQL "DELETE * FROM NameOfTable"
DoCmd.SetWarnings True

HTH
 

Rob.Mills

Registered User.
Local time
Today, 11:30
Joined
Aug 29, 2002
Messages
871
You can either create a delete query and then call the docmd.openquery in VBA

or you can run the Docmd.RunSql "Type the Sql in quotes"
 

wan2fly99

Registered User.
Local time
Today, 08:30
Joined
Feb 7, 2005
Messages
53
Thanks guys. Here I was trying to do a recordset and some other
weird stuff
 

Help4Access

New member
Local time
Today, 08:30
Joined
Oct 1, 2011
Messages
1
Taken another step further:
----------------------------
Function TruncateTable(sTableName As String) As String
' Purpose: Deletes all rows.
' Author: Help4Access.com
'
' Test: ?TruncateTable("USys_temp_RuleExport")

DoCmd.SetWarnings False
DoCmd.RunSQL "DELETE * FROM " & sTableName & ""
DoCmd.SetWarnings True

TruncateTable = SUCCESS

End Function
 

warzer

New member
Local time
Today, 18:30
Joined
Apr 18, 2017
Messages
3
I have same issue and test your suggest code and solved ,,




tanks for all


warzer hassan
 

Users who are viewing this thread

Top Bottom