The best part about queries is that you can save and run the same query again and again, but when you run the same query again and again by only changing the criteria then you might consider the query to accept parameters. Show
ExampleLet us now take a look at a simple example by creating a parameter query. Let us open your database and select Query Design in the Create table tab. Double-click on the tblProjects and close the Show dialog box. Select the field you want to see as a query result as shown in the following screenshot. In the query design grid, in the Criteria row of the ProjectStart column, type [Enter a project start data]. The string [Enter a project start data] is your parameter prompt. The square brackets indicate that you want the query to ask for input, and the text is Enter a project start data is the parameter prompt displays. Let us now run your query and you will see the following prompt. Let us now enter the following date. Click OK to confirm. As a result, you will see the details of the project which started on 2/1/2007. Let us go to the Design View and run the query again. Enter the date as in the above screenshot and click Ok. You will now see the details of the project which started on 5/1/2008. A parameter query is one where, the user supplies criteria with which to filter the results. When you run a normal query, it will return its results as soon as you run it. When you run a parameter query, it asks you to enter a value. Once you provide the value, it will continue running, using the value as part of the filtering criteria. The parameter is provided by the user at runtime. So a parameter query can return different results based on the user's input. Dates are common parameters in parameter queries. This allows the user to provide a date with which to search. Numbers are also common parameters. Parameter Query vs a Normal QueryThere's almost no difference between creating parameter queries and normal queries. The only difference is that you use square brackets For example: Will result in this prompt when the user runs the query: In this example, the date provided will be used to filter the results in the query to only those albums released after the
date provided (because the query has a greater than sign Here's a step-by-step guide to creating a parameter query.
What does it mean to enter a parameter value in Access?Sometimes when you open an Access object (such as a table, query, form, or report), Access displays the Enter Parameter Value dialog box. Access displays this dialog box when you open an object that contains an identifier or expression that Access can't interpret. In some cases, this is the behavior that you want.
|