Running delete query from Excel

G

Guest

Hi there,

From Excel I use ADO to export the Excel data to an Access table.
Before the new data may be imported, this Access table needs to be cleared,

To accomplish this I have created a delete query that deletes all records
from the table.
Currently I have to run this query manually before executing the ADO from
Excel.

Is it possible to run the delete query from Excel using VBA?
 
G

Graham Mandeno

Hi Charlie

I assume you have already opened a Connection object on your database file.

You can just use the Execute method of the Connection:

MyConnection.Execute "Delete * from [MyTable];"
 
R

RoyVidar

charlie brown said:
Hi there,

From Excel I use ADO to export the Excel data to an Access table.
Before the new data may be imported, this Access table needs to be
cleared,

To accomplish this I have created a delete query that deletes all
records from the table.
Currently I have to run this query manually before executing the ADO
from Excel.

Is it possible to run the delete query from Excel using VBA?

If you have an open connection cn, and your stored query is named for
instance qryMyDelete, you can execute it like this

cn.qryMyDelete

Else you could just fire off something like

cn.execute "DELETE FROM myTable", , adCmdText + adExecuteNoRecords
 

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