"There are 10 types of people in the world. Those who understand binary and those who do not."

Saturday 9 November 2013

Access Tip - Use a Parameter Query

Access is a very powerful database application from Microsoft.  Getting required information out of an Access database is done by using a 'Query' which will search given tables and return records displaying fields which have been specified in the query and matches given criteria.


The above simple example would return all the records from the tblEmployees table which have the surname 'Jones'.  The forename is also returned as this has been specified in the query.

All very well and, if the name to be searched for is changed to 'Smith' for example, it is relatively easy to edit the criteria accordingly - if you are comfortable with editing a query!

Turning this simple query into parameter query will  make it far easier for users who may not be familiar with Access but do know how to run a query.  So how do you make a parameter query?

Instead of 'hard coding' the name to search for in the criteria (ie "Jones") replace it with a short phrase enclosed in square brackets [ ].  The text you enter in the [ ] can be anything you like - providing it is NOT the name of an existing field in the table (In this example it cannot be 'Surname' or 'Forename').  It is a good idea to make the phrase a prompt to remind the user what to enter.


When the above query is run, the user will be presented with the following dialogue box;


Using this technique makes running queries easier for those unfamiliar with Access.

Try the following in Criteria: to give more flexibility to using parameter queries.  This example will return all surnames beginning with the letters entered (ie entering 'J' will return Jones and James.  Entering 'Jo' will return just Jones);

Like [Please enter first letter(s) of surnames to search for] & "*"

In a date field, try the following to return all records with dates in the specified range;

Between [Please enter start date] and [Please enter end date]

In this example, you will be presented with the 'Enter Parameter Value' twice (once for each date to be entered) when the query is run.


No comments:

Post a Comment