Pass a Query Parameter from the code in Access 2003

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

Guest

How do I pass parameters to a query in the forms' code?
I would like to update a table using a Query with 2 parameters.

Thanks in advance.
 
You can set the value of the parameters like this:
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Set db = CurrentDb()
Set qdf = db.QueryDefs("Query1")
qdf.Parameters("MyParameter") = MyValue
qdf.Parameters("[Forms]![Form1]![Text0]") = Forms!form1!Text0
qdf.Execute, dbFailOnError

In general, I find it easier to build the SQL statement with the literal
values patched in. It's much more flexible, e.g. where you might want to
treat some parameters as optional.

The other option if you are referring to controls on a form is to use
RunSQL, but it suffers from the limitations discussed in this article:
Action queries: suppressing dialogs, while knowing results
at:
http://allenbrowne.com/ser-60.html
 

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