Deleting all records in vba

trishcollins

Registered User.
Local time
Today, 07:02
Joined
Mar 23, 2011
Messages
42
I had been deleting and overwriting an existing table with imported data in a Event Produre on a form opening. It has worked fine for the past couple of months.

I then created a relationship between that table and another, and discovered I can no longer delete the table as it has a relationship, so I need to maintain the table structure, just delete all the records instead.

I created a Delete Query, and an saved import with the specification to "append" to the table rather than overwrite it, and both work fine when run manually.

However, calling the code from my vba does not seem to be working. It is not deleting the records first, just appending them. So, the table just keeps getting bigger. Here is the code for the delete and import (which still works fine):

Code:
 DoCmd.RunSQL "Delete_Records_From_Dynadocs"
        DoCmd.TransferText acImportDelim, "Dynadocs Inventory Import Specification", "Dynadocs Inventory", strDbPath & "Dynadocs Inventory.csv"

The code for the SQL query is:
Code:
DELETE *
FROM [Dynadocs Inventory];

Any suggestions?
 
RunSQL is for SQL, not saved queries. Try

CurrentDb.Execute "Delete_Records_From_Dynadocs"

or simply

CurrentDb.Execute "DELETE * FROM [Dynadocs Inventory]"
 
That worked. Thanks!
 

Users who are viewing this thread

Back
Top Bottom