Go Back   Access World Forums > Microsoft Access Discussion > Modules & VBA

 
Reply
 
Thread Tools Rating: Thread Rating: 8 votes, 5.00 average. Display Modes
Old 02-10-2005, 10:11 AM   #1
wan2fly99
Newly Registered User
 
Join Date: Feb 2005
Posts: 53
Thanks: 0
Thanked 1 Time in 1 Post
wan2fly99 is on a distinguished road
Code to delete records in a Table

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

wan2fly99 is offline   Reply With Quote
Old 02-10-2005, 10:25 AM   #2
daveUK
Registered User
 
Join Date: Jan 2002
Location: UK
Posts: 234
Thanks: 0
Thanked 4 Times in 1 Post
daveUK
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
daveUK is offline   Reply With Quote
The Following 4 Users Say Thank You to daveUK For This Useful Post:
Antanas_07 (02-21-2014), Bader (02-26-2014), Infinite (09-02-2015), Rx_ (02-24-2014)
Old 02-10-2005, 10:26 AM   #3
Rob.Mills
Registered User
 
Join Date: Aug 2002
Location: Raleigh, NC USA
Posts: 871
Thanks: 0
Thanked 1 Time in 1 Post
Rob.Mills
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"

Rob.Mills is offline   Reply With Quote
Old 02-10-2005, 10:40 AM   #4
wan2fly99
Newly Registered User
 
Join Date: Feb 2005
Posts: 53
Thanks: 0
Thanked 1 Time in 1 Post
wan2fly99 is on a distinguished road
Thanks guys. Here I was trying to do a recordset and some other
weird stuff
wan2fly99 is offline   Reply With Quote
Old 09-30-2011, 05:34 PM   #5
Help4Access
Newly Registered User
 
Join Date: Sep 2011
Posts: 1
Thanks: 0
Thanked 1 Time in 1 Post
Help4Access is on a distinguished road
Smile Re: Code to delete records in a Table

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
Help4Access is offline   Reply With Quote
The Following User Says Thank You to Help4Access For This Useful Post:
Rx_ (02-24-2014)
Old 04-17-2017, 11:01 PM   #6
warzer
Newly Registered User
 
Join Date: Apr 2017
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
warzer is on a distinguished road
Re: Code to delete records in a Table

I have same issue and test your suggest code and solved ,,




tanks for all


warzer hassan

warzer is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump




All times are GMT -8. The time now is 08:48 AM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Featured Forum post


Sponsored Links


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World