Excel running Access query

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have an Excel application that gets data from an Access database.

What I wish to do is run some code from Excel to automate the updating of
the Access database. Within thew Access database I have an append query set
up. How can I run this query from Excel?

Many thanks in advance.
 
Using ADO:

Dim cn As ADODB.Connection
Set cn = New ADODB.Connection

With cn
.Provider = "Microsoft.Jet.OLEDB.4.0;"
.ConnectionString = "Data Source=DBFileName"
.Open
With .Command
.CommandText = "qryName"
.CommandType = adCmdUnknown
.Execute
End With
.Close
End With
 
Many thanks

Trevor via OfficeKB.com said:
Using ADO:

Dim cn As ADODB.Connection
Set cn = New ADODB.Connection

With cn
.Provider = "Microsoft.Jet.OLEDB.4.0;"
.ConnectionString = "Data Source=DBFileName"
.Open
With .Command
.CommandText = "qryName"
.CommandType = adCmdUnknown
.Execute
End With
.Close
End With
 

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

Back
Top