1. Using Queries to Calculate Values
One
popular use for database tables is to maintain sales records with
fields for the order identifier, the product ordered, and the product’s
price. What you can’t do in a table is perform a calculation—the fields
are just designed to hold data. In a query, however, you can find
totals, averages, or even the minimum or maximum value in the records
found by your query.
1.1. Calculate a Value in a Query
Open a query in Design view.
Click Totals to add the Total row to the Query design grid.
Click the Field cell in the column in which you want to calculate the value.
Build the calculation in the Expression Builder.
Click OK.
In
the Field cell with the calculation, edit the value to the left of the
colon to reflect the name you want for the field when the query results
are displayed as a worksheet.
Note:
To select fields from other
tables for use in a calculation, double-click the Tables icon in the
left pane of the Expression Builder, double-click the table with the
target field, and then double-click the field name in the center pane.
2. Creating a Parameter Query
Some
of the time, you can create a query that always looks for the same
information, such as orders from a specific country or the total orders
from an established customer. Other times, however, you and your
colleagues need the flexibility to enter a criterion (such as a country)
into the query to focus the results correctly. You can do that by
creating a parameter query, which lets you specify the criterion the
query uses to find records.
2.1. Build a Parameter Query
Open a query in Design view.
Type
the prompt surrounded by square brackets in the Criteria cell in the
column representing the field in which you want to find the entered
value.
Click Run to test the query.
Type a value in the message box that appears.
Click OK.
Note:
If you don’t type a prompt
between the square brackets, the only indication you get to enter a
parameter is a blank dialog box. If someone unfamiliar with the database
runs the query, he or she will have no idea what to type in the box.