Create a parameter query
Use one parameter
In the Criteria cell for the field you want to use as a parameter, type an expression with a prompt enclosed in square brackets. For example, in a field that displays the current number of units in stock, enter the following:
<[Number of Units in Stock:]
Use two or more parameters
In the Criteria cell for each field you want to use as a parameter, type an expression with prompts enclosed in square brackets.
For example, in a field that displays dates, you can display the prompts "Type the beginning date:" and "Type the ending date:" to specify a range of values:
Between [Type the beginning date:] And [Type the ending date:]
Use parameters with wildcards
In the Criteria cell for each field you want to use as a parameter, type an expression with a prompt enclosed in square brackets. To prompt the user for one or more characters to search for, and then find records that begin with or contain the characters the user specifies, create a parameter query that uses the LIKE operator and the wildcard symbol (*).
For example, the following statement searches for words that begin with a specified letter:
LIKE [Enter the first character to search by: ] & "*"
The following statement searches for words that contain the specified character:
LIKE "*" & [Enter any character to search by: ] & "*"
Specify a data type for the parameters if your parameter query:
How?
On the Query menu, click Parameters.
In the first Parameter cell, type the first prompt you entered in the query design grid.
In the Data Type cell to the right, click the appropriate data type according to the following guidelines:
If the parameter field data type is | Click this data type in the Data Type cell |
---|---|
Currency, Date/Time, Memo, OLE Object, Text, and Yes/No | Currency, Date/Time, Memo, OLE Object, Text, and Yes/No |
Number | Byte, Single, Double, Integer, Long Integer, and Replication ID. These data types correspond to the five FieldSize property settings of the Number data type. |
Unknown | Value. This is a generic data type that accepts any type of data. |
Binary | Binary. Used with parameter queries directed to linked tables that do recognize this data type (Microsoft Access does not recognize this data type). |
Repeat Steps 2 and 3 for each parameter you want to specify a data type for.
To view the results, click View
on the toolbar, and then type a value for the parameter.
Create a custom dialog box to prompt for your parameter query's criteria
How?
Before you do the following procedure, create the form or report you want.
Do one of the following:
For a modeless pop-up form or report
Note The Suppliers form in Northwind sample application has an example of an event procedure that displays a modeless pop-up form. Open the Northwind database in the Samples subfolder of your Office folder, and then open the Suppliers form in Design view. Click the Build button next to the OnClick property box of the Review Products button.
For a modal pop-up form or report
To position a pop-up form or report on the screen, open it in Design view, maximize the Microsoft Access window, position the window where you want it, and then save the form or report. The pop-up window will appear in this location when the form or report is opened (assuming the AutoCenter property is set to No and you haven't specified its position in the event procedure that opens the pop-up object).
Note If you want to use a form as a normal form as well as a dialog box, you can use the Dialog setting of the OpenForm action to open the form temporarily as a dialog box instead of using this procedure.
Customer Information Example
For example, you could create a dialog box form named Customer Info with a control for the CustomerID field. By entering a customer ID in the dialog box, you could have the query return the correct customer's company name, address, and city. To create this query, you'd do the following: