MS Access - Parameter Queries


Advertisements


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.

  • If you frequently want to run variations of a particular query, consider using a parameter query

  • Parameter query retrieves information in an interactive manner prompting the end user to supply criteria before the query is run.

  • You can also specify what type of data a parameter should accept.

  • You can set the data type for any parameter, but it is especially important to set the data type for numeric, currency, or date/time data.

  • When you specify the data type that a parameter should accept, users see a more helpful error message if they enter the wrong type of data, such as entering text when currency is expected.

  • If a parameter is set to accept text data, any input is interpreted as text, and no error message is displayed.

Example

Let 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.

Temp2

Double-click on the tblProjects and close the Show dialog box.

tblprojects

Select the field you want to see as a query result as shown in the following screenshot.

Select

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.

Start Date

Let us now run your query and you will see the following prompt.

Parameter Value

Let us now enter the following date.

Enter Start Data

Click OK to confirm.

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.

Details

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.



Advertisements
E-Books Store