Parameter query

M

Mhebor

I have a query (call it query1) that contains a parameter for a date
based on a field on a form. I use this query in another query (call it
query2).

I have the following code on a button:

Set db = CurrentDb
Set qdf = db.QueryDefs("query2")
qdf.Parameters("[Forms]![rreportselector1]![startdate]").Value =
[Forms]![rReportSelector1]![startdate]
Set rst1 = qdf.OpenRecordset(dbOpenSnapshot)

When I run it, it states too few parameters, expected 1. Any parameter
I try to pass to query2 works no problem but if I put a parameter in
query1 and try to run the code, I get the error message. Any help
would be appreciated.
 
M

Marshall Barton

I have a query (call it query1) that contains a parameter for a date
based on a field on a form. I use this query in another query (call it
query2).

I have the following code on a button:

Set db = CurrentDb
Set qdf = db.QueryDefs("query2")
qdf.Parameters("[Forms]![rreportselector1]![startdate]").Value =
[Forms]![rReportSelector1]![startdate]
Set rst1 = qdf.OpenRecordset(dbOpenSnapshot)

When I run it, it states too few parameters, expected 1. Any parameter
I try to pass to query2 works no problem but if I put a parameter in
query1 and try to run the code, I get the error message. Any help
would be appreciated.


It's always been that way. Opening a recordset goes
straight to the DAO library, bypassing Access's parameter
resolution routines. But, because the second query is
opened by the first query, you have no way to tell it what
value to use for the parameter.

It is more than a little unusual to have a need to open a
recordset on a query that is based on another query, much
less one that has a paramter. If you'll explain what you
are trying to accomplish and post the two queries, maybe
someone will be able to figure how to do it a different way.
 

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