p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Access VBA (http://p2p.wrox.com/forumdisplay.php?f=80)
-   -   Deleting All Record In A Table (http://p2p.wrox.com/showthread.php?t=52323)

McDiddy January 5th, 2007 04:52 PM

Deleting All Record In A Table
I need an easy way (if there is one) to delete all the records in a table. Any Ideas???


mmcdonal January 8th, 2007 08:43 AM

Use a DELETE query.

Open the query designer, select the table you want to delete records from. Select * as the field (this will select all fields) and then on the menu bar, select Queries > Delete Query.

When you run this query, it deletes all records from the chosen table.

To run this using code (and not throw message boxes) use this:

DoCmd.SetWarnings False
DoCmd.OpenQuery "qryMyDeleteQuery"
DoCmd.SetWarnings True

Now you just have to create a button or other event to run the query.

Did that help?


McDiddy January 9th, 2007 03:38 PM

That worked perfect, thank you!

wscheiman January 10th, 2007 09:20 AM

There's another way to do this using VBA code only (if you'd like):

Dim lngRowsAffected As Long

CurrentProject.Connection.Execute "DELETE * FROM CUSTOMERS", lngRowsAffected

This not only does not require you to create a query object, but you can also check to see how many rows were deleted. I use this type of processing for INSERTs, UPDATEs, etc in a lot of my code without any problems.

In either case, both the .OpenQuery suggestion from mmcdonal and the CurrentProject approaches should work equally well. :)

All times are GMT -4. The time now is 04:12 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.