Modifying the Datasheet View of a Query
Just
as you can modify the Datasheet view of a table, you can modify the
Datasheet view of a query. You can change things such as the font, the
column order, the column widths, and the attributes of the datasheet
itself (such as background color). When you close the query, if you have
made no changes to the design of the query but you have made changes to
the layout of the datasheet, Access prompts you with the dialog box
displayed in Figure 1.
In this dialog box, Access asks whether you want to change the layout
changes that you made. If you click Yes, Access remembers the layout
changes. If you click No, Access will use the old layout the next time
that you view the query.
Saving a Query
To save a query, you click the Save button on the toolbar. The Save As dialog box appears (see Figure 2).
After you provide a name and click OK, Access saves the SQL (Structured
Query Language) statement underlying the query. It does not save the
result of the query.
The industry standard for naming queries is to prefix the name with qry.
Printing Query Results
It is easy to print query
results. Although not as elegant as a printed report, printed query
results are often sufficient to meet people’s needs. Here’s how you
print query results:
1. | Run the query whose results you want to print.
|
2. | Click the File tab.
|
3. | Select Print. Your screen should appear as in Figure 3.
|
4. | Click Print Preview. The results will appear as in Figure 4.
4 |
Closing a Query
You close a query using the
close button (the X) in the upper-right corner of the Query Design tab.
How Access responds depends on the following three conditions:
Whether you previously named and saved the query
Whether you made design changes to the query
Whether you made changes to the layout of the query while you were in Datasheet view
If you did not
previously name and save the query, Access prompts you with the Save As
dialog box when you attempt to close the query. If you previously named
and saved the query but did not make any design or layout changes to the
query, Access provides no prompts. If you made design changes or design
and layout changes, Access asks whether you want to save those design
changes. If you made only layout changes, Access asks if you want to save the layout changes.
Designing a Query Based on Multiple Tables
If
you have properly normalized your table data, you probably want to
bring the data from your tables back together by using queries.
Fortunately, you can do this quite easily by using Access queries.
The query in Figure 5
joins the Customers, Orders, and Order Details tables, pulling fields
from each. Notice in the figure that I have selected the ID and Company
fields from the Customers table, the Order ID and Order Date fields from
the Orders table, and the Unit Price and Quantity fields from the Order
Details table. After you run this query, you should see the results
shown in Figure 6.
Notice that you get a record in the query’s result for every record in
the Order Details table. In other words, there are 2,155 records in the
Order Details table, and that’s how many records appear in the query
output. By creating a multitable query, you can look at data from
related tables, along with the data from the Order Details table.
To
remove a table from a query, you click anywhere on the table in the top
half of the query design grid and then press the Delete key. You can add
tables to the query at any time by clicking the Show Table button in
the Query Setup group on the Design tab of the Ribbon. If you prefer,
you can show the Navigation Pane and then click and drag tables directly
from the Navigation Pane to the top half of the query design grid.