Deleting all table records through VBA / DAO 3.6

J

Joel Wiseheart

I use the following code to delete all records in a table
through VBA code. The problem is that since the table
contains over 47,000 records, it takes 3 minutes to run.
Is there a faster way to delete all these records?

Dim db As DAO.Database
Dim rstNew As DAO.Recordset

Set db = CurrentDb
Set rstNew = db.OpenRecordset("t_SOWOShortTrackComments")

With rstNew
If .RecordCount > 0 Then
.MoveFirst
Do
.Delete
.MoveNext
Loop Until .EOF
End If
End With
 
J

JSand42737

"Joel Wiseheart" said:
I use the following code to delete all records in a table
through VBA code. The problem is that since the table
contains over 47,000 records, it takes 3 minutes to run.
Is there a faster way to delete all these records?

Dim db As DAO.Database
Dim rstNew As DAO.Recordset

Set db = CurrentDb
Set rstNew = db.OpenRecordset("t_SOWOShortTrackComments")

With rstNew
If .RecordCount > 0 Then
.MoveFirst
Do
.Delete
.MoveNext
Loop Until .EOF
End If
End With

Joel

Rather than using a recordset, you can just execute a SQL statement:

CurrentDb.Execute "DELETE * FROM [t_SOWOShortTrackComponents];"
 
N

none

there is a quicker, easier way
dim db as dao.database

db.execute "DELETE * FROM t_SOWOShortTrackComments;"

db.close
db = Nothing
 

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