Deleting Records from another Table

N

news.microsoft.com

I want to delete all of the records from a table in the same database in
Access 2007. I want to preserve the structure of the table though.

How do I do that?
 
J

JohnC

And perhaps if you don't want to create a query object:

Dim db As DAO.Database
Dim strSQL as String

strSQL = "DELETE tablename.* FROM tablename;"
db.Execute strSQL, dbFailOnError

db.Close
Set db = Nothing

John
 
D

Dirk Goldgar

JohnC said:
And perhaps if you don't want to create a query object:

Dim db As DAO.Database
Dim strSQL as String

strSQL = "DELETE tablename.* FROM tablename;"
db.Execute strSQL, dbFailOnError

db.Close
Set db = Nothing


You forgot to set db to a reference to the current database:

Set db = CurrentDb

But you don't want to try to close the current database (even if you try,
your attempt will be ignored), so remove this line:

For that matter, the following line of code can replace all of the above:

CurrentDb.Execute "DELETE* FROM tablename", dbFailOnError
 
D

Douglas J. Steele

Dirk Goldgar said:
For that matter, the following line of code can replace all of the above:

CurrentDb.Execute "DELETE* FROM tablename", dbFailOnError

Or, to save a few keystrokes <g>

CurrentDb.Execute "DELETE FROM tablename", dbFailOnError
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top