I have a Report that is based on a query that requests a number to search for
a distinct record. How do I create a form that will contain a label for the
number, the number field to search by, and a command button to Print Preview
based on what is input in the number field?
First, create a query that will display the fields you wish to show in
the report.
Second, create a report, using the query as it's record source, that
shows the data you wish to display for ALL records.
Let's assume it is a CustomerID number you need as criteria.
Next, make a new unbound form.
Add a combo box that will show the CustomerID field as well as the
Customer Name field (you can use the Combo Box wizard to do so).
Set the Combo box's Column Count property to 2.
Hide the CustomerID field by setting the Combo box's ColumnWidth
property to 0";1"
Make sure the Combo Box Bound Column is the
CustomerID field.
Name this Combo Box "cboFindName".
Add a command button to the form.
Code the button's Click event:
Me.Visible = False
Name this form "ParamForm"
Go back to the query. As criteria, on the Query's CustomerID field
criteria line write:
forms!ParamForm!cboFindName
Code the Report's Open Event:
DoCmd.OpenForm "ParamForm" , , , , , acDialog
Code the Report's Close event:
DoCmd.Close acForm, "ParamForm"
Run the Report.
The report will open the form.
Find the CustomerName in the combo box.
Click the command button.
The Report will display just those records selected.
When the Report closes it will close the form.