Is it possible to use a combo box or a list box to select
the criteria for a query or report?
You'll need to use a form to do this.
In this example, we'll use a combo box to select a particular
Customer.
Make a new unbound form.
Add a combo box that will hold the CustomerID and the Customer Name
fields.
Hide the ID field by setting the Combo's ColumnWidths property to:
0";1"
Set the Combo's Column Count to 2
Set the Combo's Bound Column to 1
Add a command button to the form.
Code the button's Click event:
DoCmd.OpenQuery "QueryName"
DoCmd.Close acForm, Me.Name
Name this form "ParamForm"
In the Query, on the CustomerID field criteria line write:
forms!ParamForm!ComboBoxName
Make sure the Combo Box Bound Column is the
same DataType as the Query CustomerID field.
Open the form.
Find the CustomerID in the combo box.
Click the command button.
The query will display just those records selected.
The Form will close.
To use the query as the recordsource of a report, all is the same as
above, EXCEPT... code the Form's Command button:
Me.Visible = False
Code the Report's Open event:
DoCmd.OpenForm "ParamForm", , , , , acDialog
Code the Report's Close event:
DoCmd.Close acForm, "ParamForm"
Do NOT open the Form.
Run the report. The Report will open the form.
Select the Customer. Click the Command button.
The Report will display. When you close the Report, the Form will also
close.