Reputation: 187
I have an UPDATE
pass through query saved in Access 2007. When I double-click on the pass through query it runs successfully. How can I get this query to run from VBA? I'd like it to run when my "splash screen" loads.
I'm currently using the following code:
CurrentDb.Execute "Q_UPDATE_PASSTHROUGH", dbSQLPassThrough
But I get the following message:
The pass-through query contains all the connection information and I've confirmed the SQL syntax is correct by running it multiple times, so not sure what I'm missing in my VBA call.
Upvotes: 4
Views: 17433
Reputation: 95
I recently ran into the same problem. While the above mentioned Execute
method is working for most cases, some people (me included) experiencing a Run-time error '3001': Invalid Argument
when using the parameter dbSQLPassThrough. This was also addressed in the answer above me and happens even in the simplest SQL-statements.
For those who are having the same problem, I recommend using the OpenQuery
method as alternative.
A valid substitution for the following code
CurrentDb.QueryDefs("Q_UPDATE_PASSTHROUGH").Execute
would be
DoCmd.OpenQuery "Q_UPDATE_PASSTHROUGH"
I know this thread is 4 years old, however, searching for a solution for the not working Execute
method on Google brings you directly to this thread which is why I thought it would be useful to add an alternative solution which solved this problem for me.
Upvotes: 4
Reputation: 116
I confirm that the QueryDef's Execute
method is the recommended way to achieve your goal.
CurrentDb.QueryDefs("Q_UPDATE_PASSTHROUGH").Execute
However, I can point out that in a similar case with Access 2010, using dbSQLPassThrough
for the Options
parameter caused a Run-time error '3001': Invalid Argument
.
Upvotes: 1
Reputation: 97131
Use the QueryDef's Execute
method:
CurrentDb.QueryDefs("Q_UPDATE_PASSTHROUGH").Execute
I don't think you should need to explicitly include the dbSQLPassThrough option here, but you can try like this if you want it:
CurrentDb.QueryDefs("Q_UPDATE_PASSTHROUGH").Execute dbSQLPassThrough
Upvotes: 5