3

In my Access 2007 database, I've got an append query with parameters in it. How do I call this query from a VBA script?

I realize that I could just generate the query text on the fly in the VBA code, but that's much more awkward.

1 Answer 1

8

I got the following to work:

Dim db As DAO.Database
Dim qry As DAO.QueryDef

Set db = CurrentDb

Set qry= db.QueryDefs("NameOfMyStoredQuery")

qry.Parameters(0) = FirstParamValue
qry.Parameters(1) = SecondParamValue
qry.Parameters(2) = ThirdParamValue

qry.Execute
Sign up to request clarification or add additional context in comments.

2 Comments

You should also be able to use the Parameter names
Also consider qry.Execute dbFailOnError and add an error hander to your procedure.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.