- What Is a Query and When Should You Use One?
- Opening a Query in Datasheet View
- Opening a Query in Design View
- Running a Query
- Adding and Removing Fields
- Modifying the Sort Order of a Query
- Working with Simple Criteria
- Modifying the Datasheet View of a Query
- Saving a Query
- Printing Query Results
- Closing a Query
Closing a Query
You close a query by using the close button (the x) in the upper-right corner of the Query Design window. 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 Data- sheet 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 if you want to save those design changes. If you made only layout changes, Access asks if you want to save the layout changes.
Task: Working with Queries
To practice working with queries you're going to create two queries. You will base the first query on the Customers table. The query will ultimately return only salespeople in the United States and then customers in the region BC. The second query will be based on the Orders table. It will locate all orders placed within a specific date range:
Open the Customers table in the Northwind database that ships with Microsoft Access. View the records in this table.
Create a query in Design view, using the Customers table. Add all the fields to the query grid.
Sort the records in ascending order on the ContactTitle and CompanyName fields. Run the query.
Select only the records for customers in the United States. Run the query.
Add to the query criteria to show only the customers whose ContactTitle begins with Sales.
Remove the criteria for ContactTitle and Country and then change the criteria to display only the customers in the BC region.
Close and save the query, giving the query a name.
Create a query based on the Orders table.
Display all orders where the OrderDate is between 7/1/1997 and 8/31/1997. Sort the results by the OrderDate.