Carrying prompted parameter across queries

T

Tyler

Is there a way to carry a user provided parameter across
multiple queries that use the same parameter. Would only
like to enter a date range once across multiple queries.
 
P

Paul Overway

Your objective isn't apparent. Supposing you have query A that performs a
select against query B and both require a parameter named EntryDate...you
would enter EntryDate as a parameter...while in query design view, see
Query|Parameters. If the parameter has the same name in all of the queries,
it will be passed along.

If you are using queries in VBA, you would assign the parameter value to the
appropriate parameter in the parameters collection of each querydef that
requires it.
 
F

fredg

Tyler said:
Is there a way to carry a user provided parameter across
multiple queries that use the same parameter. Would only
like to enter a date range once across multiple queries.
Tyler,

Make an unbound form with whatever unbound text controls you will need.
Add a Command Button to the form.
Code it's Click event:
Me.Visible = False
Name this form 'frmDates'.

Let's say you have 2 controls on the form, one named StartDate the other
EndDate.

In each query, change the criteria of the DateField to read:
Between forms!frmDates!StartDate AND forms!frmDates!EndDate

When you need to run the queries, open this form first.
Enter the dates, click the command button.
Run the queries.

Remember to close the form when done.

As long as the form is open, each query will get the parameters from it.

Something like this is often done when running multiple reports that all
need the same parameters. If that is your intention, open the form in
the first reports Open event:
DoCmd.OpenForm "frmDates", , , , , acDialog

Then close it in the final report's Close event:
DoCmd.Close acForm, "frmDates"

Now the opening and closing of the form is automatic.
 
Top