Office 2007 - Access

Lesson 26: Paremeter Query

26/72 Lessons 

Parameter “Query”

We use a parameter “Query” when we execute the same “Query” but, with different criteria.
For example, we want to have a “Query” that gives us all orders with the product “Computers”.
Then we would normally have entered “Computers” in the criteria box for the “Products”.
We now wish to repeat this “Query”, but for another product. So, we need have a separate “Query” for each product, or change the criteria box for each Product.

By making use of a parameter “Query” this is not necessary.
Whenever you have a parameter “Query”, a dialogue window will appear where we have to enter criteria.
This can be for a single field and multiple fields.

In this example I use the “Query” made in the previous lesson, and open it in “Design View”.

I add the “Article” field from the “Products” table to the grid.
In the “Criteria” of the “Article” column, I give the text in square brackets, I want to see in the dialog window that appears when I run the “Query”.

When you click on the “Run” button in the “Ribbon”, the dialog window will ask you to type in an article.

The article that you type should naturally occur in an order, otherwise no records are displayed.

Result:

Remember to save this query under an appropriate name, such as “Total Article”.

In the following example of a parameter “Query”, I use two values.
Add the “Date” field to the “Orders” table.
This is because I want to see the orders between certain dates.
I add the “Date” field to the grid also.

In the “Criteria” of the “Date” column, I now have two options to enter.
A dialogue window with a start date, and a dialogue window with an end date.
So I type> [start date] And <[date]
That is greater than the start date and less than the end date.

When I click on the “Run” button in the “Ribbon”, I get a first dialogue window where I need to enter the start date. Then enter the value and I click OK, I get the second dialog window where I need to enter an end date.

I click the OK button again, and I get to see the result.


Be careful when entering start and end dates as this should have the same format as the one you entered as field properties for the “Date” field in the “Orders” table. So 09/21/08 is not the same as 09/21/2008.

Awesome!
You've completed Lesson 26
START NEXT LESSON