How to pass variables into existing Access queries

G

Guest

Dear ALL:

I already have about 11 queries set up that have their own parms to ask for
either a beginning and ending date or just an ending date in different fields
on the different queries. I was hoping I wouldn't have to copy all the
queries into code and put the vars inside the statements. Was hoping to pass
my dtStartDate to the Access query's [StartDate]?

On a form, I ask the user for the beginning and ending dates in txtboxes.
I have assigned those values to vars, upon clicking a Preview button, but
need to know how to pass those two vars to a query.

Once I get one query solved, I can do the rest.
 
M

Marshall Barton

Michael said:
I already have about 11 queries set up that have their own parms to ask for
either a beginning and ending date or just an ending date in different fields
on the different queries. I was hoping I wouldn't have to copy all the
queries into code and put the vars inside the statements. Was hoping to pass
my dtStartDate to the Access query's [StartDate]?

On a form, I ask the user for the beginning and ending dates in txtboxes.
I have assigned those values to vars, upon clicking a Preview button, but
need to know how to pass those two vars to a query.

Once I get one query solved, I can do the rest.


Depends on how you're going to use the query. There's an
easy way to do what you ask if you're going to open a
recordset based on the query.

If you want to just open the query in datasheet view, then
you'll have to change the query's parameters to refer to the
text boxes on the form. I.e. change [StartDate] to
something like Forms!yourform.starttextbox

If the queryies are used as the record source of a form or
report, you could use the form control references above.
But it would be better to remove the parameters from the
query and filter the dataset by using the
OpenForm/OpenReport method's WhereCondition argument.
E.g.
strWhere = "datefield >= #" & starttextbox & "#"
DoCmd.OpenForm "formname", , , strWhere
 

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