A dynamic parameter in an Access query allows for criteria to be entered by the user at runtime. This tutorial walks you through the basics of creating such a query.

Set-up

  1. Download the TXT file
  2. Import the TXT data into a new table in a new database (the data is delimited)
  3. Use the Query Wizard to create a new query based on the table, including all the fields

Simple parameter

In the simple example that follows, we want to be able to query records based on gender. We want to be able to specify Male or Female at run time.

Creating a parameterised query in Access.Running a parameterised query in Access.
  1. Create a query based on the PopStars table
  2. Add the fields you require, including the Gender field
  3. In the Criteria row for the Gender field, enter the following text: Like [Female or Male: ]
  4. Run the query
  5. The Enter Parameter Value prompt will appear
  6. Enter Female (or Male)
  7. Click the OK button
Traffic cone warning icon.

Here is a REAL gotcha! You cannot use a parameter that is the same as the field name. In other words, in the Gender field, your parameter cannot be [Gender]. It must be [Enter your gender] or even just [Gender:]

Parameter with wildcard

Now replace the criteria in the Gender field in the query above with the following: Like [F(emale) or M(ale): ] & "*"

The & (ampersand) is Access’ concatenator. It “joins” strings together — in this case, it joins the user’s input with the * (wildcard) operator to form the criteria.

You will now only need to enter F (or M) to obtain the same results.

Dynamic parameters can be combined with static parameters.

Next steps

Coming soon: Create a Crosstab Query in Access


References:

  1. Microsoft Support. (2014) Use parameters to ask for input when running a query. Available at: https://support.microsoft.com/en-us/office/use-parameters-to-ask-for-input-when-running-a-query-c2806d3d-d500-45a8-8507-ec6af351b6ed (Accessed: 18 June 2023).

By MisterFoxOnline

Mister Fox AKA @MisterFoxOnline is an ICT, IT and CAT Teacher who has just finished training as a Young Engineers instructor. He has a passion for technology and loves to find solutions to problems using the skills he has learned in the course of his IT career.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.