Reports - To send a value to an input box

  • Thread starter Thread starter Randy Fritz
  • Start date Start date
R

Randy Fritz

Hello NG,

I have 2 reports that, through code, I print 3 times each. The only
difference between the 2 reports is the query that the reports draw its
information from. I want to put in the Report Open Event an input box that
allows the user to select Query1 or Query2 and then print the report. My
question resides in my code that automatically prints both reports 3 times.
Can I send Query1 or Query2 to the report that, upon opening, overrides the
inputbox with the criteria sent? If yes, Can someone help me along with how?

TIAFAH
Randy
 
Randy,
I think the way I would do this is to start from a form.
Have the form open the report.
The report runs and then closes the form when done.

Make a new unbound form.
Add an Option group with buttons to select which query you want as the
report's record source,'Query1' or 'Query2'.
Include whatever text controls you need to pass parameters to the query.
Add a Command button and code it's click event:
DoCmd.OpenReport "ReportName", acViewPreview
Me.Visible = False

In each query, as criteria for a field, use the
forms!FormName!ControlName
syntax.

Delete the current Report Record Source.

Next code the Report's Open event:
Select Case forms!FormName!OptionGroupName
Case is =1
Me.RecordSource = "Query1"
Case is = 2
Me.RecordSource = "Query2"
End Select

Code the Report's Close event:
DoCmd.Close acForm, "FormName"

Enter the criteria into the form text controls, select the query using the
Option Group buttons, and click the command button.

I you do not wish to close the form after the report is run, don't close the
form in the Report Close event code.
Instead write:
forms!FormName.Visible = True

The report will close and display the form again.
 
Back
Top