Share this Page URL

Chapter 6. Sorting, Filtering, and Retri... > Using a Parameter Query - Pg. 221

Sorting, Filtering, and Retrieving Data 221 Using a Parameter Query In a parameter query, you can specify criteria when you run the query rather than include the criteria in the query's design. A parameter query displays an input box when you run it, and then you enter a value or an expression that fits the parameter you've defined. In the expense report query, for example, we can use a parameter to specify the campaign whose expenses we want to see. By using a parameter, we don't need to store a separate query for each campaign or alter the query's design when we want to see records for a specific campaign. You can enter a parameter in more than one field in a query. In the expense report query, we could include one parameter to specify the campaign and another parameter to define the date range for the expenses we want to view. When you define a parameter, you also indicate the parameter's data type so that Access recognizes whether the value you enter for the parameter is valid. Too much of a good thing Using more than one parameter in a query provides flexibility, letting you select a specific set of records when you run the query. To avoid asking a user to enter data into a sequence of input boxes, you can also base a form on a parameter query and let the user select the values for the parameters all at once on the form. For more information about building forms, see Chapter 7, "Designing Basic Forms." In the steps that follow, we'll create a parameter query for the expense report query. Create a parameter query 1. 2. Open qryExpenseReport in Design view. In the Criteria row under Country, enter [Enter a campaign country], as shown here: