Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete SQL table contents via VBA 1

Status
Not open for further replies.

jmcg

Technical User
Jun 30, 2000
223
GB
I have a local access database that I send up to an SQL db using:
Code:
db.Execute "INSERT INTO [ODBC;DRIVER=SQL Server;SERVER=MyServer;DATABASE=MYDatabase].MyTable( Field1, Field2 ) SELECT lclFld1, lclFld2 FROM lclTable
and it works fine, however before uploading the new data I need to clear down the old data.
I have tried:
Code:
db.Execute "DELETE FROM [ODBC;DRIVER=SQL Server;SERVER=MyServer;DATABASE=MYDatabase].MyTable
and get an error 3622:
You must use the dbSeeChanges option with OpenRecordset when accessing a SQL Server table that has an IDENTITY column.
I tried removing the IDENTITY col and got an error saying could not delete from specified tables.
Any help, much appreciated.
 
The syntax should be something like:
Code:
CurrentDb.Execute("YourDeleteQueryStatement",dbSeeChanges)

You need to have a primary key defined for the table (probably your Identity column) in order to delete from Access.
 
Robert
Thanks a lot worked perfectly.
PS: The syntax was without the brackets :-O
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top