Problem Solving Uding Access 2007
Problem Solving Uding Access 2007
LEARN IN G OUT C O ME S
Introduction
A query is a tool for extracting, combining, and displaying data from one or more ta-
bles, according to criteria you specify. For example, in a book inventory database, you
could create a query to view a list of all hardcover books with more than 500 pages that
you purchased in the past five months. In a query, you can sort information, summarize
data (display totals, averages, counts, and so on), display the results of calculations on
data, and choose exactly which fields are shown. You can view the results of a query in
a tabular format, or you can view the query’s data through a form or on a report (which
is covered in Plug-In T8, “Decision Making Using Access 2007”). In this plug-in, you will
learn how to use the Query Wizard and Query-By-Example (QBE) tool to solve problems
using Microsoft Access 2007.
3. Click the Create tab and then click the Query Wizard button.
4. In the New Query dialog box, select Simple Query Wizard and then click OK.
5. Once the wizard opens, click the Tables/Queries drop-down arrow. Select Table:
CUSTOMER (refer to Figure T7.1).
6. Add all the fields by clicking on the right double arrow (>>) button.
7. Click Next.
8. In the next window, make sure the radio button Detail is selected and click Next.
9. In the next window, type Customer Query as the Query title and select the radio but-
ton for Open the query to view information.
10. Click Finish to view the query in Datasheet view (refer to Figure T7.2).
11. Close the query (it will automatically be saved).
By modifying the query in Design view, you can specify that the query display only
records that meet certain criteria or that the query display records in a specific order.
*
Note: Keep in mind that a query database object stores only the query definition—
field names, data selection criteria, sorting orders, grouping information, and so on. It
does not store the actual data that it displays; that data is stored only in the database
tables. Consequently, every time you run a particular query, it shows the current state of
the data stored in the database tables.
FIGURE T7.2
Query in Datasheet
View
3. Notice the dark, thick column border line that appears to the left of the selected column.
As you move your mouse across the screen, the column border line will move with it.
4. Close and save the query.
Note: You can select adjacent columns by clicking a field selector and dragging the
mouse across other field selectors, then clicking one of them again to drag the whole
selection.
FIGURE T7.4
Query in Design View
Table
and
field
list
Query
design
grid
You can add tables to the field list by clicking the toolbar button or selecting Show
Table from the Query Setup group of the Design tab menu.
FIGURE T7.6
Criteria for a Select Query
Advanced Queries
Database fields generally display the data that are entered into them. However, a calcu-
lated field will automatically figure its value based on values in other fields. Queries often
include calculated fields that display values based on other values returned by the query.
To enter formulas in calculated fields, follow these steps:
1. Click the Create tab and then click the Query Design button.
2. Click the names of the BIKE, CUSTOMER, and RENTAL tables in the Navigation
Pane (hold down the CTRL key to select each one). In the Show Table dialog box that
appears, click the Add button.
3. Click the Close button to continue.
4. Double-click the Last Name and First Name fields from the CUSTOMER table,
double-click the Date field from the RENTAL table, and double-click the Description
field from the BIKE table.
5. To add a new calculated field, click inside the field row of a blank column, and type
Rental Amount:—this is the name of an anonymous field (it is actually a variable
name to hold the value of the calculated field).
6. Now you will enter the expression to be calculated. Type in: ([Time In]-[Time
Out])*24*[Cost Per Hour] (refer to Figure T7.7). Note: When referring to a field name,
enclose the name in brackets. You can use standard mathematical operator symbols like
* (multiplication), / (division), + (addition), − (subtraction), and ^ (exponentiation).
7. Click on the Show check box under the Rental Amount column.
8. Run the query (click Run button in toolbar) to see the results of the calculated field.
9. Close and save the query as Rental Amount.
Note: When using a calculated field to combine text fields, you usually want to hide
the text fields that are being combined and show only the new calculated field.
Update To:
row
FIGURE T7.12
Query Type Warning
A
query is a tool for extracting, combining, and displaying data from one or more tables,
according to criteria you specify. You can use the Query Wizard or Query-By-Example
tool to select specific data from a table or tables. You can sort the rows of a query by a
particular field, hide a particular field, enter a value to search on, summarize information, and
even modify data using a query.
1. ProSwing Analysis
Carol Redden had been a part-time tennis instructor for several years. Frustrated with the
tennis equipment available in the market, she started her own company. With the aid of her
attorneys and investors, she founded ProSwing to design tennis equipment and apparel.
Carol developed a strong product line and was becoming successful in the United
States, but she was having trouble with the firm’s international marketing strategy. Carol
thought that the most effective way to advertise was by getting players to use and wear
her products. She wanted to be sure that the players using her line were the players fol-
lowed by the fans (her target market). She knew that this would bring ProSwing attention
from tennis players around the world. She decided to concentrate on the tennis players
with the highest current winnings, since they were likely to be very popular and visible to
the fans. She would approach the top 25 international men and women players about using
ProSwing products. She would then additionally advertise during tennis matches in the
four countries most represented by the top players in order to represent both the men and
women top players.
Carol prepared a database after finding recent sport statistics on the Web and compiled
data on the top players. Included in the database are the player’s name, country of resi-
dence, most recent winnings, and gender. Carol needs your help to organize the data to
plan her international strategy. She has provided you with the database file T7_ProSwing_
Data.mdb in order to complete the following:
1. Create a query that will sort the player data in descending order by winnings. Save the
query as Player Winnings Query.
2. Create a query that will sort the data in ascending order by Country Name and then in
descending order by Winnings within each country. Change the order of the columns
so that Country is the first column, followed by Winnings, and then Player. Save the
query as Country Winnings Query.
3. Create a query that will total the winnings for each country. Use the Country Name for
the criteria and sort the Winnings in descending order. Save the query as Total Win-
nings for Country Query.
2. WasteNot Recycling
WasteNot Recycling is an organization that picks up recyclables from homeowners in
Boulder, Colorado, as introduced in Plug-In T6. The CUSTOMER table holds static cus-
tomer information such as name, address, and phone. The CUSTOMER RECORD table
holds data about each recyclable pickup. Enough test data has been added to each table to
test queries (use the T7_WasteNotRecycling_Data.mdb file associated with this text).
4. BookFinder.com
BookFinder.com is an open marketplace for books online, a one-stop e-commerce search
engine where you can search through more than 100 million new, used, rare, and out-of-
print books for sale.
The site is produced by a team of high-tech librarians and programmers, working since
2004 to connect readers with the books they are looking for. They are part of their own
audience; members of the BookFinder.com team are heavy readers and buy several dozen
books every year using BookFinder.com. They also blog about their work, connecting read-
ers and booksellers from around the world and supporting public access to a strong, di-
verse bookselling industry.
BookFinder.com was first developed in 2004 by then-19-year-old University of Denver
undergraduate Charles Cook (as a personal Web site). Over the years, the site has grown
to become one of the best online resources for book-related e-commerce, as evidenced