Using parameters with queries and reports

M

Michael

Using parameters with queries and reports

I'm using a form to supply data to a parameter query. When I run the
report, it opens the form, I enter the data to pass to the query, click "ok"
it hides the form, runs the query and displays the resut in a datasheet query
view instead of the report. The report is never displayed.
 
R

Rick Brandt

Michael said:
Using parameters with queries and reports

I'm using a form to supply data to a parameter query. When I run the
report, it opens the form, I enter the data to pass to the query, click "ok"
it hides the form, runs the query and displays the resut in a datasheet query
view instead of the report. The report is never displayed.

If the report is bound to the query then there is no need to "run" the query.
Just remove that line of code and replace it with a line that opens the report.
Normally you would open such a form first and have it open the report rather
than having the report open the form. At that point it might be too late for
the report to make use of the parameter.
 
F

fredg

Using parameters with queries and reports

I'm using a form to supply data to a parameter query. When I run the
report, it opens the form, I enter the data to pass to the query, click "ok"
it hides the form, runs the query and displays the resut in a datasheet query
view instead of the report. The report is never displayed.


The query is the record source for the report?
Here is an example that uses a Start date and End date as parameters
for the report record source (the query).

Create an unbound form.

Add 2 unbound text controls.
Set their format to a valid date format.
Name them "StartDate" and "EndDate"

Add a Command Button to the form.
Code the button's click event:

Me.Visible = False

Name this form 'ParamForm'.

As criteria in the query date field write:
Between forms!Paramform!StartDate and forms!ParamForm!EndDate

Next, code the report's Open event:
DoCmd.OpenForm "ParamForm", , , , , acDialog

Code the report's Close event:
DoCmd.Close acForm, "ParamForm"

When ready to run the report, open the report.
The form will open and wait for the selection of the Company and the
entry of the starting and ending dates wanted.
Click the command button and then report will run.
When the report closes, it will close the form.
You never 'see' the query.
 

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