DBWebApplications 





Refining Access Queries  «Prev  Next»
Lesson 3 Creating parameter queries
Objective Use a parameter with your query to specify criteria dynamically.
In the last lesson, you saw a query in Design view that had the criterion TX for the State field.
This is fine if you are going to use TX for the criterion forever or don’t mind opening the query in Design mode to change the criteria value, but chances are you will want to query on different criteria. Ideally, you could set the field you want to specify criteria for, and be able to specify the criteria values when you run the query. A parameter query will let you do exactly that. Note that you can use parameters for criteria and calculated expressions, but not for specifying whether to sort. Nor can you use them for the name of a field in a query.
For example, to create a parameter query that will allow you to specify different states whenever you run it, first create a query on the Clients table, as you would for any other query. Next, instead of specifying TX for the criteria row of the State field, you can type [Enter State:] in the criteria row of the State field. Now, when you open the query in Datasheet view by clicking the View toolbar button, a dialog box will open asking you to Enter State, as was specified. When you type the state you want, and there are some records that match, Access will display those records.
In addition to standard comparison operators (<, >, =, <=, >=), you can use some advanced operators when defining your parameters.
Besides text, you can also use parameters for numbers and dates. You can use parameters as part of calculated expressions as well.
In the next lesson, you will learn how to use multiple criteria in a query using the AND and OR operators.

Creating Parameter - Query

Click the exercise link below to see how to create a parameter query using the Clients table and the State field.
Creating Parameter - Query