Access 2007 Queries

UNIVERSITY INFORMATION TECHNOLOGY
TRAINING & DOCUMENTATION DEPARTMENT
DOING MORE WITH ACCESS
2007: ADVANCED QUERIES
AND REPORTS
University Information Technology Training & Documentation Department
2
Table of Contents
Introductory Notes ............................................................................................. 4
Action Queries ................................................................................................... 5
Update Query .................................................................................................... 5
Delete Query ................................................................................................... 10
Creating a Calculated Field ............................................................................. 16
Making Modifications to a Query.................................................................. 19
Wildcards ..................................................................................................... 20
Make-Table query ........................................................................................... 21
Append query .................................................................................................. 27
Find Duplicates Query Wizard ......................................................................... 32
Find Unmatched Query Wizard ....................................................................... 34
Crosstab query ................................................................................................ 37
Parameter query ............................................................................................. 41
Moving Data To and From Excel ..................................................................... 48
Exporting Data to Excel ............................................................................... 48
Importing Data from Excel ........................................................................... 49
Creating a Report ............................................................................................ 53
Modifying a Report in Design View .............................................................. 58
Adding a Graphic to a Report ...................................................................... 64
Adding a Chart to a Report .......................................................................... 66
Sorting and Grouping Report Data .............................................................. 69
University Information Technology Training & Documentation Department
3
Doing More with Access 2007: Adv. Queries & Reports
INTRODUCTORY NOTES
“Doing More With Access: Advanced Queries and Reports” assumes that you
have completed “Getting Started with Access,” offered by our Training
Department. Therefore, basic terminology and navigation will not be addressed
in this course. Rather, this course picks up where “Getting Started” left off,
focusing on advanced data manipulation and reports.
“Doing More With Access: Advanced Queries and Reports” was designed for
end-users who would like more tools at their disposal for manipulating data and
producing polished reports. Throughout today’s session, the following topics will
be covered:
•
Creating an Update Query
•
Creating a Delete Query
•
Creating a Calculated field
•
Creating a Make-Table Query
•
Creating an Append Query
•
Using the Find Duplicates Query Wizard
•
Creating a Crosstab Query
•
Creating a Parameter Query
•
Using AutoReport
•
Creating Summary Reports
•
Modifying Reports
University Information Technology Training & Documentation Department
4
Doing More with Access 2007: Adv. Queries & Reports
ACTION QUERIES
A query is a way to define a particular group of records. Think of a query as a
request or a way to draw out information, an analysis tool. For example, “Show
me the names of all employees hired within the last 30 days." There are several
different types of queries, but all serve the same purpose - to get answers to
questions about the data that is stored in a database. In the Getting Started
class, we covered Select Queries. Today we will cover Action Queries. Select
Queries merely display data; Action Queries change, and then display the data.
Here is a list of the Action Queries we will cover today:
Update Query: a query that makes universal changes to a group of
records in one or more tables. For example, you could increase the prices
of all wood products in a table by 5%.
Delete Query: a query that deletes a group of records from one or more
tables. For example, you could delete any records that are more than five
years old in a table.
Make-Table Query: a query that creates a new table from existing records
in one or more tables. For example, you could create a new table as a
backup or you could create a new table with selected records for export.
Append Query: a query that adds a group of records to the end of an
existing table. For example, you could avoid retyping a list of customers
from another table by "appending" the list to your existing customers table.
UPDATE QUERY
An Update Query is a query that will make global changes to a select group of
records based on criteria that you determine. Instead of manually filtering
records in a table, and then editing the records, an update query will
automatically perform the same function. For example, if wood products have
increased by 5%, running the update query will update only those records
pertaining to wood products, increasing their value by 5%.
University Information Technology Training & Documentation Department
5
Doing More with Access 2007: Adv. Queries & Reports
We have a collection of pets at our house that include fish. Each of the pets has
a monetary worth, reflected in the “Value” field in the Access database. We want
to update the values of just the fish by 10%. An update query will be used to
accomplish this.
To create an update query:
1. Open the Pets database.
2. Open the Pets table. Nine records display, composed of fish, birds, and
amphibians.
3. Close the Pets table.
4. On the Navigation Pane, click Queries. Only one Select query, the
qryFish query, displays.
5. Open the Fish Query. Five records display in a dynaset.
Note that the prices in the Value field are whole dollar amounts.
6. On the Home tab, click the View tool.
displays in Design view.
The
query
Design View: Design view is one of the possible ways to view data.
Design view gives you access to the "design" elements of the datasheet or
object that you are working with. In Design view, you can set up the
guidelines for displaying data.
University Information Technology Training & Documentation Department
6
Doing More with Access 2007: Adv. Queries & Reports
7. Note on the Query Tools Design tab, in the Query Type group, that this is
currently a Select query.
We are now going to set up the criteria to update the value of the fish records by
10%.
8. Before we change this query, notice the two fields, Sort and Show on
the QBE grid.
QBE grid: this is the Query By Example grid, or area, in the lower half of
the screen. The grid is composed of columns, or fields, and rows. The
type of query you are running will determine the rows.
9. On the Query Tools Design tab, in the Query Type group, click the
Update tool. On the QBE grid, the Sort and Show rows have been
replaced with Update To:
University Information Technology Training & Documentation Department
7
Doing More with Access 2007: Adv. Queries & Reports
The qryFish Select query is now an Update query.
Try clicking the Select query tool again in the Query Type group, keeping your
eyes on the QBE grid. Notice the row headings change from Update To to Sort
and Show.
Now return to the Update Query option.
10. In the Value column (7th field in the grid), place the cursor in the Update
To field.
11. Type the expression [value]*1.1 (This will add 10% to their values).
Expression: an expression is a combination of symbols that produces a
result. [value]*1.1 is an expression. In our example [value] represents
the value field in our Pets table. The symbol * is an operator, which will
perform multiplication. The 1.1 is a value representing our wish to
increase the value field by 10%.
12. Press Enter. The cursor moves to the next blank field.
You are now ready to run the Update query.
13. On the Query Tools Design tab, in the Results group, click the Run
tool.
Access has a warning for you. The number of rows to be updated is
indicated. In this case, it is five. This process cannot be undone.
Always verify changes to tables especially when you are updating
many records.
University Information Technology Training & Documentation Department
8
Doing More with Access 2007: Adv. Queries & Reports
14. Click Yes. Note that the view does not change to display the results of the
update, and we're still in Design view. Action queries work this way, as
opposed to the Select queries we ran in the Getting Started class. No
dynaset or subset of records is displayed.
15. In the upper-right corner of the Update query, click the Close button
.
Access asks if you want to save changes to the design of the query
qryFish.
16. Click No. The query closes.
Why? Remember that an Action query, and in this case it's an Update
query, changes data. If you save the query, and someone runs the query
by mistake, the same records may be changed in error. For example, if
this Update query was saved, and someone ran the query again, all of the
values of the fish would be increased by another 10%.
If you did decide to save the new Update query, its icon in the Navigation
pane would reflect an exclamation mark, which would differentiate it from
a Select query.
To review the changed data:
17. On the Navigation pane, select Tables. The Pets table is listed.
18. Open the Pets table. Note the records that have been updated (the fish)
and the 10% increase in value for the fish.
19. Close the Pets table.
University Information Technology Training & Documentation Department
9
Doing More with Access 2007: Adv. Queries & Reports
DELETE QUERY
A Delete query is a query that deletes a group of records from one or more
tables. For example, you could delete any records from a table that are more
than five years old. Databases accumulate quantities of old, outdated data and a
delete query is a tool to keep your databases clean.
Delete queries are also commonly used with archive-type operations. By using
the Append or Make-Table query in conjunction with the Delete query, you can
transfer outdated records to a history table.
Before deleting records, a safe step is to back up your database:
1. Click the Microsoft Office Button
, select Manage, and then,
under Manage this database, click Back Up Database. The Save
As dialog box opens.
2. In the Save As dialog box, specify a name and location for the
backup copy, and then click Save. Access closes the original file,
creates a backup, and then reopens the original file.
We are going to delete all of the bird records from the Pets table.
Before we create the Delete query, let's look at our original Pets table before we
delete any records.
1. On the Navigation pane, open the Pets table. We currently have 5 fish
records, 3 bird records, and 1 amphibian record listed in our table.
2. Close the Pets table.
To create a delete query:
3. On the Create tab, on the right end of the ribbon, in the Other group, click
the Query Design tool. The QBE grid and Show Table window open.
Queries can be created from tables or other queries.
University Information Technology Training & Documentation Department
10
Doing More with Access 2007: Adv. Queries & Reports
4. In the Show Table window, on the Tables tab, click the table tblPets.
5. Click Add. The Pets table is brought into the QBE grid.
6. Click Close. The Show Table window closes.
To convert the default Select query into a Delete query:
7. On the Query Tools Design tab, in the Query Type group, click the Delete
tool. On the QBE grid, the Sort and Show rows have been replaced with
Delete:
In review, you select fields that you wish to incorporate into your query from the
Pets table and move them into the QBE grid using one of three methods: doubleclick, drag-and-drop, or drop-down menu.
We will review all three methods as we bring all of the fields (PetID, Animal,
Type, Color, Name?, Quantity, and Value) from the Pets field list into the QBE
grid. In particular, the Animal field must be brought into the QBE grid as this is
the field that holds the specific deletion criteria, the animal type that we want to
delete.
8. In the tblPets field list, double-click the PetID field. The PetID field
appears in the first column of the grid.
9. In the tblPets field list, select the Animal field by clicking and holding.
10. Drag the Animal field to the second column of the grid. The Animal
field appears in the second column of the grid.
University Information Technology Training & Documentation Department
11
Doing More with Access 2007: Adv. Queries & Reports
11. Click in the next available Field row (third column on the grid). The
empty field displays a drop-down arrow.
12. Click the dropdown arrow. The tblPets field names appear.
13. Select Type. The Type field appears in the third column of the grid.
14. Using whichever method is most comfortable for you; select the
following additional fields for inclusion in your query:




Color
Name?
Quantity
Value
Your QBE grid should look like this:
The next step is to add the criteria that will delineate or define the records to be
deleted.
15. In the Animal field, in the Criteria field below "Where" type bird. Case
does not matter, although spelling does.
University Information Technology Training & Documentation Department
12
Doing More with Access 2007: Adv. Queries & Reports
Warning: Never leave the criteria field empty or blank. If you run the query with
the criteria field empty, all your records will be deleted!
16. On the Create tab, in the Results group, click the Run tool. Again you
are warned and the number of rows or records to be deleted is indicated
(in our case, three).
TIP - Testing the Delete Query
If you would like to see what records will be deleted before you actually click
"Yes" and commit, try this:
1. Click "No." The warning closes.
2. Double-check to make sure that your criterion is entered in the
Criteria field.
3. On the Create tab, in the Results group, click the View tool. This will flip
you over to Datasheet view.
You will see a preview of all the records about to be deleted. Once you
have determined that the query will select ONLY those records needing to
be deleted:
4. Click the View tool again. You are returned to the Design View to the
Delete query in progress.
17. Click the Run button again if you tried the above tip.
University Information Technology Training & Documentation Department
13
Doing More with Access 2007: Adv. Queries & Reports
18. Click Yes. The screen remains in the Design view.
19. Close the unnamed, unsaved Delete Query.
20. Click No, to not save this query (again, for security sake). The query
closes.
To view the updated table data:
21. In the Navigation pane, click Tables and open the tblPets table. The 3
bird records have been deleted, leaving 6 records.
The delete query is also useful for deleting records within time periods:
For example, typing the expression "<1/1/2000" in the Criteria row of a date field
would delete all records prior to 1/1/2000 or every record from 1999 back in time.
The following table from the MS Help offers additional selection criteria:
Criteria
Effect
> 234
Returns all numbers greater than 234. To find all numbers
less than 234, use < 234.
>= "Cajhen"
Returns all records from Cajhen through the end of the
alphabet.
Between
#2/2/2007# And
#12/1/2007#
Returns dates from 2-Feb-2007 through 1-Dec-2007.
Not "Germany"
Finds all records where the exact contents of the field are
not exactly equal to "Germany." The criterion will return
records that contain characters in addition to "Germany,"
such as "Germany (euro)" or "Europe (Germany)".
Not "T*"
Finds all records except those beginning with T.
Not "*t"
Finds all records that do not end with t.
In(Canada,UK)
In a list, finds all records containing Canada or UK.
Like "[A-D]*"
In a Text field, finds all records that start with the letters A
through D.
University Information Technology Training & Documentation Department
14
Doing More with Access 2007: Adv. Queries & Reports
Like "*ar*"
Finds all records that include the letter sequence "ar".
Like "Maison
Dewe?"
Finds all records that begin with "Maison" and contain a 5letter second string in which the first 4 letters are "Dewe"
and the last letter is unknown.
#2/2/2007#
Finds all records for February 2, 2007.
< Date() - 30
Uses the Date function to return all dates more than 30
days old.
Date()
Uses the Date function to return all records containing
today's date.
Between Date()
And DateAdd("M",
3, Date())
Uses the Date and the DateAdd functions to return all
records between today's date and three months from
today's date.
Is Null
Returns all records that contain a null (blank or undefined)
value.
Is Not Null
Returns all records that contain any value (that are not
null).
""
Returns all records that contain a zero-length string. You
use zero-length strings when you need to add a value to a
required field, but you don't yet know what the actual value
is. For example, a field might require a fax number, but
some of your customers might not have fax machines. In
that case, instead of entering a number, you enter a pair of
double quotation marks with no space between them ("").
22. Close the tblPets table.
Finally, you use delete queries only when you need to change or remove large
amounts of data quickly. If you want to remove a small number of records— any
quantity that you feel comfortable deleting by hand— you can open the table in
Datasheet view, select the fields or rows that you want to delete, and press
Delete.
University Information Technology Training & Documentation Department
15
Doing More with Access 2007: Adv. Queries & Reports
CREATING A CALCULATED FIELD
In a query, you can create a new field (or column) that will display the results of a
calculation called a calculated field. Calculated fields are used to display the
results of computations based on numeric fields in the table. Although the results
of a calculation are shown in the dynaset, the fields do not exist in any
permanent location in the underlying tables. They exist only in the query where
they are created.
Remember that tables are best utilized for storing data safely, while queries dig
into your data and provide analysis.
When you create a calculated field in a query there are a few rules that you must
follow:
•
•
•
All calculations are placed in the Field row in the QBE (Query By
Example) Grid.
Fields used in the calculation must be surrounded by the square
bracket [ ].
The field name cannot be exactly like any others found in the table.
1. On the Navigation pane, in the Queries group, open the qryFish query.
The data displays in Datasheet view.
Before we create the calculated field, we will resize the columns.
2. Place the cursor on top of the PetID Field Selector so that it becomes
a black down-facing arrow.
3. Click and drag across the seven field names (column headings) so that
all seven are selected.
4. Place the cursor between any of the gray field names so that it
becomes a double-headed black resizing cursor and double-click.
This will AutoFit the columns and gives you more room on the screen to
work.
5. Click the View tool to go into the design of our qryFish query.
6. Repeat the same resizing steps here in Design view. The columns are
thinner, providing more room to work on the screen.
University Information Technology Training & Documentation Department
16
Doing More with Access 2007: Adv. Queries & Reports
We will create a calculated field that will reflect the total value of different fish
types.
7. In Design view, in the QBE grid, click in the next available Field cell (8th
column, top cell).
8. Hold down the Shift key and press the F2 key. This opens the Zoom
box and gives us plenty of space to see all of our typing.
If you make any typos at this point, it will create an error, so we are going to
make a typing error on purpose. We will create the calculated field with a typo.
9. Type Total Value: [Quantity]*[Valu] .
Total Value is your new field name. [Quantity] and [Value] are existing
fields. If you misspell an existing field's name, (in our case, the field name
Value) you will get an error. Again, we are making an error on purpose.
The phrase Total Value: [Quantity]*[Valu] is an expression.
10. Press Enter or click OK. The Zoom Box closes.
To run the query and view the calculated field:
11. Click the Run tool
Value” dialog appears.
. The query runs and an “Enter Parameter
University Information Technology Training & Documentation Department
17
Doing More with Access 2007: Adv. Queries & Reports
This is what you will see if you've made a typing error, although there are times
when you will want to see this (such as in the creation of a Parameter query,
which is upcoming):
The best way to clean up this error is to do the following:
12. Click Cancel. The Enter Parameter Value dialog closes.
13. Press Shift F2. The Zoom box opens.
14. Look for any typos.
This is the main reason for the Enter Parameter Value dialog box coming up at
this point. Note that Access has provided a clue by listing the term it does not
recognize (Valu).
15. Add the final "e" to the field name Value.
16. Click OK. The Zoom box closes.
University Information Technology Training & Documentation Department
18
Doing More with Access 2007: Adv. Queries & Reports
. The query runs, and Access 2007 multiplies
17. Click the Run tool
each of the values in the Value field by the corresponding values in the
Quantity field to produce the new values, displaying the new field "Total
Value."
If you wish to change the name of the calculated field, you must first enter the
new name, and then a colon, followed by the calculation.
18. Save the query.
M AKING M ODIFICATIONS TO A Q UERY
So far, we have modified an existing query. Now we will modify a query and
save it as a different distinct query.
We will modify the qryFish so that it will only return fish with black as one of their
colors. It will be saved as qryBlackFish.
1. Click the View tool. The view changes to Design view.
Resize the columns if you need to so that you can see all the data.
2. In the Color field (4th column), click in the Criteria cell.
3. Type black.
4. Press Enter. The cursor moves to the next cell and the term black is
surrounded by quotation marks.
University Information Technology Training & Documentation Department
19
Doing More with Access 2007: Adv. Queries & Reports
We have narrowed the search criteria by adding an additional search term.
5. Click the Run tool
. One record is returned. Note that the Angel
fish record bearing “Black and White” in the color field was not returned.
6. On the keyboard, press the F12 key (shortcut for File: Save As). The
Save As dialog box opens.
7. In the Save 'qryFish' to: field, type qryBlackFish.
8. Click OK. The new query is saved.
W ILDCARDS
A wildcard is a special symbol that represents one or more characters. You can
use a wildcard to select records that contain certain characters or parts of words.
Two of the available wildcard characters are * and ? .
For example:
east*
will return any records beginning with east
*east
will return any records ending with east
*east*
will return any records with east in the middle
fl?me
will return records such as flame or flume where one
character is inserted
f??me
will return records such as frame or flume where two
characters are inserted
When we ran the qryBlackFish above, using the search term “black,” the “black
and white” record was not returned.
•
Try using a wildcard (i.e. black*) in the qryBlackFish query.
Typing “wildcard” in the Access Help
characters.
will bring up additional search
We will use wildcards later in a Parameter query.
University Information Technology Training & Documentation Department
20
Doing More with Access 2007: Adv. Queries & Reports
9. Close the new query.
If the collection of fish changes in the future, whenever the qryBlackFish query is
run, it will always return up-to-the-date results. You can also go into the query to
modify it to select red fish, for example.
MAKE-TABLE QUERY
A Make-Table query does just that: it creates a new table using data from one or
more existing tables based on the results of a Select query. One application of a
make-table query is to create a table of records that you are about to delete (like
a history table). You can hold onto the table until you are sure you don't need the
records you are about to purge.
The Make-Table query’s dynaset is a brand new table composed of duplicate
data. The records contained in this table are no longer linked to the original, nor
are the original records deleted.
To create a Make-Table query:
1. On the Create tab, on the right end of the ribbon, in the Other group, click
the Query Design tool. The QBE grid and Show Table window open.
Queries can be created from tables or other queries.
2. In the Show Table window, on the Tables tab, click the table tblPets.
3. Click Add. The Pets table is brought into the QBE grid.
4. Click Close. The Show Table window closes.
University Information Technology Training & Documentation Department
21
Doing More with Access 2007: Adv. Queries & Reports
To convert the default Select query to a Make-Table query:
5. On the Query Tools Design tab, in the Query Type group, click the Make
Table tool. The Make Table dialog box displays:
You are prompted to name the new table and decide where you want the
table to reside.
6. Name this table "tblNoFish."
This table will be composed of any records from the tblPets table that are not
fish. We will set the criteria to pull those records shortly.
We'll leave it in the current database (the default).
7. Click OK. The Make Table dialog box closes:
You are ready to proceed with the Make Table query.
To bring all of the fields from tblPets into the QBE grid:
8. From the field list, click PetID. The PetID field is selected.
University Information Technology Training & Documentation Department
22
Doing More with Access 2007: Adv. Queries & Reports
9. Hold the shift key down and scroll down in the field list and click on
the last field "Value". All the fields that you want to add to the query are
selected.
10. Click in the orange selected area and drag all of the fields at once
into the first field in the first column in the QBE grid. All 7 fields are
added to the grid.
To set criteria that will return only non-fish records:
11. Click in the Criteria field in the Animal column and type "Not Like
fish." "Not Like" is an operator that is used to compare (a comparison
operator).
or type <>fish
Again, case does not matter, but spelling does matter.
University Information Technology Training & Documentation Department
23
Doing More with Access 2007: Adv. Queries & Reports
12. Press Enter.
Before the Make-Table query is run, the following three tables list a variety of
arithmetic, comparison, and logical operators that can be used in Access queries.
An operator is a sign or symbol that specifies the type of calculation to perform
within an expression.
Arithmetic operators
Operator
Purpose
Example
+
Sum two numbers.
[Subtotal]+[SalesTax]
-
Find the difference between
two numbers or indicate the
negative value of a number.
[Price]-[Discount]
*
Multiply two numbers.
[Quantity]*[Price]
/
Divide the first number by
the second number.
[Total]/[ItemCount]
\
Round both numbers to
integers, divide the first
number by the second
number, and then truncate
the result to an integer.
[Registered]\[Rooms]
Mod
Divide the first number by
the second number, and
then
return
only
the
remainder.
[Registered] Mod [Rooms]
^
Raise a number to the
power of an exponent.
Number ^ Exponent
University Information Technology Training & Documentation Department
24
Doing More with Access 2007: Adv. Queries & Reports
Comparison operators
Operator
Purpose
Example
<
Returns True if the first value is
less than the second value.
Value1 < Value2
<=
Returns True if the first value is
less than or equal to the second
value.
Value1 <= Value2
>
Returns True if the first value is
greater than the second value.
Value1 > Value2
>=
Returns True if the first value is
greater than or equal to the second
value.
Value1 >= Value2
=
Returns True if the first value is
equal to the second value.
Value1 = Value2
<>
Returns True if the first value is not
equal to the second value.
Value1 <> Value2
Operator
Purpose
Example
And
Returns True when Expr1 and
Expr2 are true.
Expr1 And Expr2
Or
Returns True when either Expr1 or
Expr2 is true.
Expr1 Or Expr2
Eqv
Returns True when both Expr1 and
Expr2 are true, or when both Expr1
and Expr2 are false.
Expr1 Eqv Expr2
Not
Returns True when Expr is not
true.
Not Expr
Xor
Returns True when either Expr1 is
true or Expr2 is true, but not both.
Expr1 Xor Expr2
Logical operators
University Information Technology Training & Documentation Department
25
Doing More with Access 2007: Adv. Queries & Reports
To run the query and make the tblNoFish table:
13. Click the Run tool
. Access tells you how many records will be
added (pasted), which is the one amphibian record.
14. Click Yes. The record is copied into the new tblNoFish table and because
this is an action query, you remain in Design view.
15. Close the Make-Table query. You are asked if you want to save changes
to the design of the query.
16. Click No, don't save the query. The query closes.
17. On the Navigation pane, click back to your Tables and open up your
new table "tblNoFish." The one copied record displays.
The data is copied. If you were creating the table as an archive, you can now run
another query such as a Delete query. Again, when you run a Make-Table
query, data is copied, not deleted or moved.
18. Close the NoFish table.
University Information Technology Training & Documentation Department
26
Doing More with Access 2007: Adv. Queries & Reports
APPEND QUERY
An Append query will add a group of selected records into an existing table. For
example, you need to bring a list of customers from another table into your
existing customers table. Instead of retyping the list, you can "append" the list to
your existing customers table. You also have the ability to selectively bring in
only the fields you need into your existing table.
We will append a table of fish from another database into the tblPets table.
To view the data to be appended:
1. In the class files folder, open the FerociousFish database.
2. Open the table tblFerociousFish. Five records display.
3. Close the tblFerociousFish and the FerociousFish database.
To create the Append query:
4. On the Create tab, on the right end of the ribbon, in the Other group, click
the Query Design tool. The QBE grid and Show Table window open.
Since the tblFerociousFish has not been imported into this database, it will not
display in the Show Table window.
5. Close the Show Table window. The Show Table window closes.
University Information Technology Training & Documentation Department
27
Doing More with Access 2007: Adv. Queries & Reports
To import the tblFerociousFish table:
6. On the Ribbon, click the External Data tab.
7. In the Import group, click the Access tool. The Get External Data Access Database window opens.
8. Check the option “Import tables, queries,… into the current
database.”
9. In the File Name field, click Browse. The File Open window opens.
10. On the Desktop, in the class files folder, select the FerociousFish
database.
11. Click Open. The path displays in the File Name field.
12. Click OK. The Import Objects window opens.
13. In the Import Objects window, on the Tables tab, click to select
tblFerociousFish.
University Information Technology Training & Documentation Department
28
Doing More with Access 2007: Adv. Queries & Reports
14. Click OK. The tblFerociousFish table is imported and the Save Import
Steps window opens.
15. Close the Save Import Steps window.
If you choose to save the import steps, you can quickly retrieve
the same table and save time through the Saved Imports tool.
To add the table tblFerociousFish to the query:
16. On the Ribbon, on the Query Tools Design tab, in the Query Setup group,
click the Show Table tool. The Show Table window opens.
17. Add the table tblFerociousFish.
18. Close the Show Table window.
19. On the Query Tools Design tab, in the Query Type group, click the
Append tool. The Append dialog box displays.
University Information Technology Training & Documentation Department
29
Doing More with Access 2007: Adv. Queries & Reports
In the Table Name field, the name of the table in which we want the records to be
appended needs to be entered.
20. In the Table Name field, click the down-arrow and select tblPets.
Leave it in the current database.
21. Click OK.
Note that the tblFerociousFish table only has five fields. You can append as
many or as few as you like. There may be superfluous information that you do
not need in your table.
You can only append fields to other fields if they have the same Data Type, such
as Text or Currency. If you attempt to append one data type to another, Access
will return a “type conversion failure” error.
22. Bring all five fields into the QBE grid.
Access displays the table that the records will be appended to as well as the
name of the field that the data will be appended to.
If you wish to append records with a different field name than the field in the table
to be appended to, but the same data type, you may.
23. In the ID field, click the down-arrow in the Append To field (reveals all
of the possible fields) and select PetID. The fields are matched up.
University Information Technology Training & Documentation Department
30
Doing More with Access 2007: Adv. Queries & Reports
At this point, if you would like to double-check to see what records are going to
be appended to the end of the tblPets table, click the View tool, and you
can preview the records in Datasheet view. Click the View tool again to
return to Design view and the query in progress.
To run the query:
24. Click Run. You will be warned that you are about to append 5 rows.
25. Click Yes. The records are appended, although it appears that nothing
has happened since this is an action query.
26. Close the Append query.
27. Don't save the design. The query is not saved.
28. On the Navigation pane, in the Tables, open the tblPets table. The 11
records display including the 5 appended records.
There are a few things to note. The appended records only had five fields, not
the seven fields represented in the tblPets table. There was no Value field in the
tblFerociousFish so those records were assigned a value of $0.00. There was
no Name? field either, so those fields are empty.
Be careful when appending records because a zero value or a blank field may
mean something (such as a pH or donation amount) and be misinterpreted.
The records were sorted by PetID alphabetically as PetID is the primary key.
University Information Technology Training & Documentation Department
31
Doing More with Access 2007: Adv. Queries & Reports
FIND DUPLICATES QUERY WIZARD
Using the Find Duplicates query, you can determine if there are duplicate
records in a table, or determine which records in a table share the same value.
For example, you might search for duplicate values in an address field to
determine if you have duplicate records for the same supplier, or you might
search for duplicate values in a city field to see which suppliers are in the same
city.
We will use this wizard to search for any duplicate records in the color field of the
tblPets table.
Before we launch the Find Duplicates Query Wizard:
1. Note that there are two sets of duplicate records in the Color field,
two green and two black records.
2. Close the tblPets table.
3. On the Create tab, on the right end of the ribbon, in the Other group, click
the Query Wizard tool. The New Query window opens.
4. Select Find Duplicates Query Wizard.
5. Click OK. The wizard opens.
In this first (of four) screen you determine if it's a table, query, or both that you
want to look through for duplicates. Try clicking the 3 different option buttons.
6. Select the tblPets table.
7. Click Next. The next step of the wizard opens.
University Information Technology Training & Documentation Department
32
Doing More with Access 2007: Adv. Queries & Reports
The second screen, "Which fields might contain duplicate information?" is where
we will choose the field that may have duplicate values.
8. From "Available fields:" click the Color field.
9. Click the right facing arrow. The Color field is moved to the Duplicatevalue fields area.
If you chose both the Color and the Name? fields, would the query yield any
results? No, because Access would be looking for duplicate pet records that
have both the same color and name. The more fields that you select, the smaller
the search results of duplicates will be.
If you chose both the Color and the Animal fields, would the query yield any
results? Yes, because we have 2 records that meet both criteria (Green and
Fish).
10. Click Next. The third screen of the wizard appears.
Do you want to see any additional fields in our results? Bring in all the additional
fields just in case they might be needed for reference. This will give us more
information for evaluation.
11. Click the double arrows
to bring all six of the other fields into the
Additional query fields right-hand window.
12. Click Next. The last step of the wizard displays.
13. Rename this query "qryColorDuplicatesPets.”
University Information Technology Training & Documentation Department
33
Doing More with Access 2007: Adv. Queries & Reports
14. Leave the default option "View the results." The query will display in
Datasheet view.
15. Click Finish. Two sets of duplicate records are returned: two black and
two green.
Note that the field with the duplicate information is the first column.
This query is displaying live data. If you make any changes to the query data,
such as delete records, it will be reflected in the parent table.
16. Close the query. The query is added to the query list.
The query is automatically saved so that it can be run again at a later date. This
is a select query so our original table, tblPets and the records within it, have not
been affected in any way.
FIND UNMATCHED QUERY WIZARD
You may have a need to compare two tables and identify records in one of the
tables that have no corresponding records in the other table. The tool to use to
identify these records is the Find Unmatched Query Wizard. For example, you
could compare a Customers table to a CustomerOrders table to determine which
customers have no orders. The Find Unmatched Query Wizard allows you to
select the matching fields in two different tables.
Before launching the Find Unmatched Query Wizard, take a look at the
difference in records between the two tables:
1. Open the tblPets table.
2. Note that there are 11 records, reflecting 11 different animals.
University Information Technology Training & Documentation Department
34
Doing More with Access 2007: Adv. Queries & Reports
3. Close the tblPets table.
4. Open the tblPetsOrders table.
5. Note that there are 8 records.
6. Close the tblPetsOrders table.
We will use the Find Unmatched Query Wizard to determine which animals have
not been ordered.
7. On the Create tab, on the right end of the ribbon, in the Other group, click
the Query Wizard tool. The New Query window opens.
8. Select Find Unmatched Query Wizard.
9. Click OK. The wizard opens.
In this first (of five) screen you determine if it's a table, query, or both that you
want to look through for unmatched records. Try clicking the 3 different option
buttons.
10. Select the tblPets table.
11. Click Next. The next step of the wizard opens.
The second screen, "Which table or query contains the related records?" is
where you select the table or query that contains unmatched records.
12. Select the tblPetsOrders table.
University Information Technology Training & Documentation Department
35
Doing More with Access 2007: Adv. Queries & Reports
13. Click Next. The next step of the wizard opens.
The third screen, "What piece of information is in both tables?" is where you
select a field common to both tables.
14. In both fields, select PetID.
15. Click the two-sided arrows
Matching fields field.
. The matching fields appear in the
16. Click Next. The next step of the wizard opens.
The fourth screen of the wizard, “What fields do you want to see in the query
results?”, allows you to bring in additional fields just in case they might be
needed for reference. This will give us more information for evaluation.
17. Click the double arrows
to bring all seven of the other fields into the
Selected fields right-hand window.
18. Click Next. The last step of the wizard displays.
19. Rename this query "qry PetsWithoutMatchingPetOrders.”
University Information Technology Training & Documentation Department
36
Doing More with Access 2007: Adv. Queries & Reports
20. Leave the default option "View the results." The query will display in
Datasheet view.
21. Click Finish. The query results display.
Three fields are unmatched, or have no corresponding record matches in the
parent tblPets table.
This query is displaying live data. If you make any changes to the query data,
such as delete records, it will be reflected in the parent table.
22. Close the query. The query is added to the query list.
CROSSTAB QUERY
In Access you can create a special kind of query known as a Crosstab query
which you use to summarize numeric or currency data in a spreadsheet-like
format. A Crosstab query is another tool for "breaking out" information.
Information is displayed in a row and column format, which makes it easier to
analyze. A crosstab query looks like a table. You determine the row and column
fields or headers. Where the rows and columns intersect, Access will return a
value. The crosstab query also gives you an extra calculating column.
We will set up a Crosstab query that will present us with a table-like look to view
the quantity of different kinds of pets we have by color.
To create a Crosstab query using the Wizard:
1. On the Create tab, on the right end of the ribbon, in the Other group, click
the Query Wizard tool. The New Query window opens.
University Information Technology Training & Documentation Department
37
Doing More with Access 2007: Adv. Queries & Reports
2. Select Crosstab Query Wizard.
3. Click OK. The wizard opens.
In this first (of five) screen you determine if it's a table, query, or both that you
wish to build the query from.
4. In the first screen, select the tblPets table. The tblPets table holds the
valuable data.
5. Click Next. The next step of the wizard opens.
Use this screen to choose the fields we want for the row headings running
horizontally. You may select up to three fields.
6. Select the Color field. The sample builds.
7. Click Next. The next step of the wizard opens.
In this third step or screen, choose the column heading or field that will run
vertically.
University Information Technology Training & Documentation Department
38
Doing More with Access 2007: Adv. Queries & Reports
8. Select Type. The Sample Crosstab builds.
9. Click Next. The next step of the wizard opens.
In this fourth screen, Access is looking for the number or calculation result to be
returned where the row and columns intersect.
10. Select Value in the Fields list and Count in the Functions list. This will
return a count of the different colors.
Leave the checkbox for including row sums checked. That will generate an
extra column.
11. Click Next. The last step of the wizard opens.
12. Name the qry qryPets_Crosstab.
13. Click Finish. The resulting Crosstab query displays.
University Information Technology Training & Documentation Department
39
Doing More with Access 2007: Adv. Queries & Reports
The colors are represented in the rows, and the type of pet is represented in the
columns. The number calculated at the row and column intersection is the total
for the various colors.
Let's clean this up before we close it. Notice the second column heading, "Total
of Value," is not clear. This is a default, what Access has assigned until you
change it. We'll change the second column heading to "Total of Color."
14. To toggle to Design view, on the Home tab, click the View tool. The
query displays in Design view.
15. Click in the in the fourth column in the Field row of the QBE grid that
begins "Total of Value: [Valu]."
16. Double-click the first instance of the word "Value." Value is selected.
17. Type the word Color.
18. Click the View tool. The query displays in Datasheet view and the
summary column is adjusted.
19. Resize the Total of Color column as needed.
We can now close the qryPets_Crosstab: Crosstab query.
20. Click the close button. The query closes
21. Select Yes. The design changes are saved.
University Information Technology Training & Documentation Department
40
Doing More with Access 2007: Adv. Queries & Reports
PARAMETER QUERY
If you run the same queries over and over (with nothing more than changes to
the criteria each time you run the query), you can convert the query to a
Parameter query, and save the time of having to open and modify the criteria
each time you want to run the query. A Parameter query is a type of query that
asks for information "up front." Once you open or run the query, you will be
presented with one or more dialog boxes that ask you for information. This
information is called the parameters or criteria that limit the results of the query.
For example, you may have a query that displays all the transactions that have
taken place within your department for a number of years. Instead of setting the
parameters once you have the query open, such as a specific fiscal year, you
can type the parameters (or limits) before the query opens. Then, when the
query opens, you have your range of records presented to you.
We will set up two parameter queries. The first one will prompt the user to enter
the color or colors of pets. This way, only the records that match those
parameters (or colors) will be returned. Secondly, we will set up a parameter
query based on value (price) that will prompt the user to type in a range of dollar
amounts. The query will return a listing of pets that fall within that numerical
range.
We will create these two new parameter queries from scratch.
1. On the Create tab, on the right end of the ribbon, in the Other group, click
the Query Design tool. The QBE grid and Show Table window open.
2. In the Show Table window, on the Tables tab, click the table tblPets.
3. Click Add. The Pets table is brought into the QBE grid.
4. Click Close. The Show Table window closes.
5. Bring all the fields from the Pets fields list into the QBE grid.
University Information Technology Training & Documentation Department
41
Doing More with Access 2007: Adv. Queries & Reports
We will now proceed to set up our parameters. This query will require a color or
colors to be entered to run the query.
6. Click in the Criteria cell in the Color field (4th column, 5th cell).
7. Type Like [What color?].
What you have just typed, What color?, will be the prompt in the dialog box the
next time this query is run. You will see this prompt when this parameter query is
run in a moment. The user will then enter the parameters that will define the
query results.
Note that the text of your prompt cannot match the field name exactly. If you did
match the field name exactly, you would no longer have a parameter query. You
can include the field name as part of your prompt, as we have. You can also
simply add a question mark after the field name if you wish. Try to make your
prompts user friendly.
To run the parameter query:
8. Click the Run tool
displays.
. The Enter Parameter Value dialog window
This is the prompt What color? that you just set up.
9. Type blue. Case does not matter.
University Information Technology Training & Documentation Department
42
Doing More with Access 2007: Adv. Queries & Reports
10. Click OK. One record is returned for the Neon.
11. Close the query. You are prompted to save the query.
12. Click Yes to save the query. The Save As window opens.
13. Name this query qryColorSelection.
14. Click OK. The parameter query is saved.
To test the qryColorSelection parameter query with another color:
1. Open (double-click) the qryColorSelection query. The What color?
prompt appears requesting the parameters or limits of your query.
2. Type black.
3. Press Enter or click OK. Any pets with black as one of their colors will
be returned. Two records display.
4. Close the query.
1. Open the ColorSelection parameter query again. The What color?
prompt appears requesting the parameters or limits of your query.
2. Type white.
3. Press Enter or click OK. No records return.
What do you notice?
No records match the parameter value "white," although there is a fish in our
database that is partially described as "whitish."
4. Close the query.
University Information Technology Training & Documentation Department
43
Doing More with Access 2007: Adv. Queries & Reports
To experiment with a wildcard character:
1. Open the query again. The What color? prompt appears requesting the
parameters or limits of your query.
2. Type whit*.
3. Press Enter or click OK. The “Whitish” color record displays.
Do be careful of your spelling. If you misspell a word, the query will still run, and
will return invalid data.
TIP – Keyboard Shortcut to Rerun the Parameter Query
If you would like to run the parameter query again using different parameters
without closing and reopening it:
1. With the previous query results still displaying, press Shift and F9. The
What color? prompt appears, ready to accept new parameters.
4. Close the query.
We will continue by building another parameter query that requires a range of
criteria and will display two different prompts when it is run.
University Information Technology Training & Documentation Department
44
Doing More with Access 2007: Adv. Queries & Reports
We will begin by making a copy of the qryColorSelection query.
1. On the Navigation bar, right-click the qryColorSelection query. The
shortcut menu opens.
2. From the shortcut menu, select Copy.
3. Right-click anywhere in a free (white) section of the Navigation bar. The
shortcut menu opens.
4. From the shortcut menu, select Paste. The Paste As dialog box opens.
5. In the Paste As dialog box, type qryValueRange.
6. Click OK. The new parameter query is added to the query list.
7. On the Navigation bar, in the Queries list, right-click the qryValueRange
query. The shortcut menu displays.
8. On the shortcut menu, select Design View. The query opens in Design
view.
University Information Technology Training & Documentation Department
45
Doing More with Access 2007: Adv. Queries & Reports
We will retool the query.
9. In the Color field, delete the criteria "Like [What color?]".
10. In the last field (column) Value, click in the Criteria cell.
You are going to enter criteria that will allow you to see a range of records
returned when the query is run.
11. To zoom in, press Shift-F2 (this will give us room to work). The Zoom
window opens.
12. Type the expression: between [Lowest value?] and [Highest value?]
13. Click OK. The Zoom window closes.
14. Run the query. The Lowest value? prompt appears requesting the
parameters or limits of your query.
The first parameter is entered here. We will enter two values signifying
dollar amounts that we wish to spend.
15. Type 1 (signifies one dollar).
University Information Technology Training & Documentation Department
46
Doing More with Access 2007: Adv. Queries & Reports
16. Press Enter or click OK. The second prompt displays.
This is where the last parameter will be entered.
17. Type 3 (signifies three dollars).
18. Press Enter or click OK. Three records are returned with dollar values
that fall within the parameters of the query, one dollar and three dollars.
19. Close the qryValueRange query.
20. Save the changes to the new design.
Try going back into the design of the ValueRange parameter query and
experiment with different parameters.
Note: Entering “Is Null” in the criteria field will return any records with
empty or blank fields.
University Information Technology Training & Documentation Department
47
Doing More with Access 2007: Adv. Queries & Reports
MOVING DATA TO AND FROM EXCEL
Data collected in Access may need to be moved to Excel and vice versa. Excel’s
number crunching capabilities can be utilized and then the data can be returned
to Access. The following steps will take you through both processes.
E XPORTING D ATA TO E XCEL
You can export table or query data to Excel. When exporting data to Excel, a
copy of the data is exported. To export Access data to Excel:
1. In the Navigation Pane, select the tblPets table (the object that contains
the data that you want to export).
2. On the External Data tab, in the Export group, click Excel.
Export – Excel Spreadsheet wizard opens.
The
3. In the File name field, accept the suggested name for the Excel
workbook (Access uses the name of the source object), or rename the
file.
4. In the File Format field, accept the suggested file format or select
another Excel format.
5. Click OK.
displays.
The file is exported and the Save Export Steps window
University Information Technology Training & Documentation Department
48
Doing More with Access 2007: Adv. Queries & Reports
6. Click Close.
7. To view the new Excel data, open the Excel file.
I MPORTING D ATA FROM E XCEL
You may import Excel data into a new or existing Access table. In Access 2007,
you can now import in one operation using the Import Wizard to walk you through
the import steps.
If you encounter errors during the import, Access alerts you. For example, there
may be a duplicate ID in a primary key field. You can either make the changes in
the Excel workbook and re-import the data, or make the changes in the new
Access table.
Access stores the imported data without altering the Excel data.
Before beginning the import process:
1. Check the Excel table data (in our case, the MorePets Excel file). Make
sure that:
a) All of the columns have headers.
b) There are no blank or empty rows.
c) The column data is consistent (i.e. all numeric or all dates).
Note that formulas do not import.
University Information Technology Training & Documentation Department
49
Doing More with Access 2007: Adv. Queries & Reports
To import Excel data into Access:
2. In Access, on the External Data Tab, in the Import group, click Excel. The
Get External Data — Excel Spreadsheet window opens.
3. In the File name field, click Browse. The File Open window opens.
4. Navigate to the Excel file (in our case, MorePets) and click Open. The
file path appears in the File name field.
5. Select the first option, Import the source data into a new table in the
current database.
Selecting the second choice, Append a copy…, would merge the Excel
records into an existing Access table, such as tblPets.
6. Click OK. The first Import Spreadsheet Wizard window opens.
7. Select the worksheet that you want to import (we have only one) and
click Next. The next step of the wizard opens.
If more worksheets existed in the Excel workbook, it might look like this:
8. In this window, check to make sure that the “First Row Contains
Column Headings” check box is selected and click Next. The next
step of the wizard opens.
The Excel column headers will become the Access field names.
University Information Technology Training & Documentation Department
50
Doing More with Access 2007: Adv. Queries & Reports
The third window of the wizard provides customization options. The field options
are:
Field Name: If you need to change any column names, click the column
and enter a new name in the Field Name box.
Data Type: You can set a data type for each field, though Access will do
that for you. In Access, data types control what you can enter into a field.
For example, you can't enter text in a field set to contain numbers, and
that helps keep your data accurate.
Indexed: If you search a column frequently, and that column has a lot of
data, click the column, and from the Indexed list, select Yes. Indexing a
column can make it easier and faster to find data.
Do not import field: If you want to remove a column or columns from the
import operation, click the column and select the Do not import field (Skip)
check box.
9. After making any changes, click Next. The next step of the wizard opens.
Primary keys are important because they make each row or record in the table
unique, and that helps ensure accuracy in your data because you can't enter
duplicate information.
If you wish to have the wizard create a primary key, accept the default “Let
Access add primary key.” You may also choose to have no primary key. We will
use an existing column, PetID, which has unique entries, as our primary key.
10. Select Choose my own primary key and select the PetID field.
11. Click Next. The next step of the wizard opens.
12. In the Import to Table field, type a name for the new table (i.e.
tblMorePets).
13. Click Finish. The Save Import Steps window opens.
14. Click Close. The table is added to the table list.
University Information Technology Training & Documentation Department
51
Doing More with Access 2007: Adv. Queries & Reports
15. As a final step of safety, open the new table in Access and review the
data. Does it have any errors? Did all the records import? How is the
formatting?
16. Close the tblMorePets table.
University Information Technology Training & Documentation Department
52
Doing More with Access 2007: Adv. Queries & Reports
CREATING A REPORT
Once you have completed the work and processes involved in drawing out the
data you need using tables and queries, you are ready to produce a report. A
report is a polished, professional way to present your data and findings. For
some individuals, this report may be the only data they will see as a reflection of
all your work. The report function gives you precise control over organizing and
formatting the data's presentation.
Since we want to create a polished report that reflects the contents of our pet
collection as it now stands, we will use the Report Wizard. The wizard sketches
out the outline and content areas for our report. You may have to tweak or refine
the results of the Wizard's work. There are a number of tools available to alter
the look or format of the report. Some of these tools are summary options,
graphics, formatting tools and charts. We will change the formatting of field
labels and fields, add a graphic and a chart, and we'll look at some summary
options.
To create a report:
1. On the Create tab, in the Reports group, click the Report Wizard tool.
The Report Wizard opens.
2. In the Tables/Queries field, make sure that the tblPets is selected.
Reports can be generated from tables or queries.
3. From the Available Fields list, select every field but PetID and Name?
(five fields).
4. Click Next. The grouping levels step of the wizard opens.
The "Do you want to add any grouping levels?" step allows you to select field
names so that the report can be divided into sections or groups. This provides
University Information Technology Training & Documentation Department
53
Doing More with Access 2007: Adv. Queries & Reports
organization for the report so that it is not pure detail. For example, a report
could organize the record detail to display registrants by month or year. Note
that before we promote a field that the Grouping Options button in the lower left
corner of the window is grayed out.
To set up grouping levels:
5. Select Animal and click the right facing arrow. The Animal field is
promoted.
Note that the Grouping Options are now enabled.
6. Click Next. The sort order and summary information step of the wizard
opens.
This is the step in the Wizard where sort order and summary information for the
detail of our records can be adjusted. Note that below the fourth available field
that there is a Summary Options button.
7. Click Back. The grouping levels step reopens.
8. Demote Animal. There are now no grouping levels.
University Information Technology Training & Documentation Department
54
Doing More with Access 2007: Adv. Queries & Reports
9. Click Next to move on again. The sort order and summary information
step reopens.
Note that below the 4th field that the Summary Options button is gone. To utilize
this tool, you must have grouping levels in the previous step.
10. Click Back again. The grouping levels step reopens.
11. Promote Animal again.
12. Click Next. The sort order and summary information step of the wizard
reopens.
13. In the first field, click the down-arrow and select Type. This will sort the
detail portion of the records by Type.
14. Click the Ascending button a few times to view the two sort choices.
15. Select Ascending. This will sort the records in A-Z order.
16. Click the Summary Options button.
opens.
The Summary Options window
University Information Technology Training & Documentation Department
55
Doing More with Access 2007: Adv. Queries & Reports
In the Summary Options window, any fields with numerical values will appear
with the options to find the sum, average, minimum or maximum of the values in
their respective fields.
17. Check the Sum checkboxes next to the Quantity and Value fields.
In the "Show" area on the right-hand side of the window, leave the default "Detail
and Summary" option selected. This will show all the detail of the records as well
as the summary we are looking for. If you were to choose "Summary Only", you
would lose the detail.
18. Click OK. The Summary Options window closes.
19. Click Next. The layout step of the wizard opens.
Adjustments can be made to the layout of the detail of the report and to the page
orientation.
20. Accept the defaults and click Next again. The style step of the wizard
opens.
University Information Technology Training & Documentation Department
56
Doing More with Access 2007: Adv. Queries & Reports
There are 25 styles to choose from. You can make supplementary style
adjustments once the report is generated, so you are not locked into a set style.
21. Choose Access 2007 for the style.
22. Click Next. The last step of the wizard opens.
23. On this final step, name the report "rptPets."
24. Leave the option “Preview the report” selected.
25. Click Finish. The report displays in Print Preview.
Notice the grouping by Type, sort order, banded rows, layout problems, and
detail and summary information. Access has calculated the total number of
animals and the total value of the collection.
We will proceed to clean up and reformat this report. We will remove the
summary totals for the Animal field, but will leave the grand totals.
26. On the far right side of the ribbon on the Print Preview tab, click the
Close Print Preview tool. Access displays the report in Design View.
University Information Technology Training & Documentation Department
57
Doing More with Access 2007: Adv. Queries & Reports
M ODIFYING A R EPORT IN D ESIGN V IEW
This report has seven sections:
Report Header: This is like a cover sheet for a fax. Access places this
page at the beginning of a report to display title, introduction, etc.
Page Header: In contrast to the Report Header, the Page Header displays
information such as page numbers or column headings at the top of every
page.
Animal Header or Group Header: This information placed at the beginning
of a group of records introduces the group. This information would not be
here if we had not promoted Animal when we were using the report
wizard.
Note that Access places the above three sections with its partner, the
Footer (Report Footer, Page Footer, and Animal Footer).
Detail: this is a listing of the individual records.
If we had created a report from scratch in Design View, we would have begun
with just three default sections: Page Header, Detail, and Page Footer.
The Animal Footer section contains the calculations we will remove.
1. Using your mouse, move the cursor to the left of the Animal Footer
information so that it hovers over the vertical ruler and turns to a black
right-facing arrow.
2. Aiming at the first line of text (an expression), click and drag down to
select both lines of text. Yellow outlining appears around all of the text
and objects.
University Information Technology Training & Documentation Department
58
Doing More with Access 2007: Adv. Queries & Reports
3. On the keyboard, press Delete. The Animal footer information is
removed.
To view the results:
4. Click the View tool down-arrow and select Print Preview. The report
displays in Print preview and the Animal Footer calculations are removed,
but the Grand Total remains.
The next step is to eliminate some of the empty space and adjust the columns so
that data is not truncated on this one page report. We will accomplish this by
sliding the Animal and Type columns to the right and the Quantity and Value
columns to the left.
5. On the far right side of the ribbon on the Print Preview tab, click the
Close Print Preview tool. Access returns to Design View.
6. In the Page Header section, click the Color label. The Color label and
the Color detail field are selected.
7. Place the cursor on the right-hand side of the Color label. A
horizontal double-headed resizing arrow appears.
University Information Technology Training & Documentation Department
59
Doing More with Access 2007: Adv. Queries & Reports
8. Drag the right border of the Color label to the left to resize it. The
Color Label and field are now smaller in width and the Quantity and Value
columns have moved to the left.
To view your adjustment:
9. Click the View tool down-arrow and select Print Preview. The report
displays in Print preview.
10. On the far right side of the ribbon on the Print Preview tab, click the
Close Print Preview tool. Access returns to Design View.
We have been using Print Preview and Design View to fine-tune the Pets report.
Two other options for making design changes are Report View and Layout View.
Print Preview presents an accurate look at how the report will print. Report View
is much like Print Preview except that all of the elements are visible, but not
necessarily positioned as they will print out.
Layout View is a more visually-oriented view than Design view. There are
plusses and minuses to using Layout view over Print preview. One plus is that
while viewing a report in Layout view, each control, such as the Color field,
displays real data. One minus is that certain tasks cannot be performed in
Layout view and require switching to Design view.
We will make the next adjustment in Layout view.
11. Click the View tool down-arrow and select Layout View. The report
displays in Layout view.
12. Click the blue Animal field. The two field headers are selected.
University Information Technology Training & Documentation Department
60
Doing More with Access 2007: Adv. Queries & Reports
13. Drag the right border of the Animal field to the right to resize it so that
the whole word “Amphibian” is visible. The field headers are now wider in
width and readable.
14. Click the blue Type field. The field is selected.
15. Drag the right border of the Type field to the left. The extra white
space is removed.
16. To view the report, click the View tool down-arrow and select Report
View. The report displays in Report view.
17. Follow the same steps to expand the Value column out to the right
(repeat steps 11-13 above, beginning in Layout view). This opens up
some room between the two columns and makes the report more legible.
18. Click the View tool down-arrow and select Layout View. The report
displays in Layout view.
University Information Technology Training & Documentation Department
61
Doing More with Access 2007: Adv. Queries & Reports
19. At the bottom right corner of the report, click the Grand Total 19 sum
field that should be lined up under the Quantity field. The field is selected
in yellow.
20. Using the four-headed move arrow, drag the Grand Total 19 sum field
to the left so that it is lined up under the Quantity field.
The Grand Total for the Value field is truncated, so it displays the # symbol. To
resize it:
21. Click the Grand Total for the Value field. It is highlighted in yellow.
22. Using the two-headed horizontal resize arrow, resize the Grand Total for
the Value field.
23. Using the four-headed move arrow, drag the Grand Total for the Value
field to the left so that it is lined up under the Value field.
To change the formatting of the Grand Total for the Value field to currency:
24. Click the Grand Total for the Value field. It is selected.
University Information Technology Training & Documentation Department
62
Doing More with Access 2007: Adv. Queries & Reports
25. On the Report Layout Tools, Format tab, in the Formatting group, click
the Currency tool. Currency style is applied to the field.
The footer information now needs to be moved in to the left.
accomplished in either Design or Layout view.
This can be
26. Using the four-headed move arrow, drag the Page numbering field to
the left so that it is lined up under the Value field as well.
27. To view the report adjustments, click the View tool down-arrow and
select Report View. The report displays in Report view.
The extra gray and white banding on the right side of the report can also be
removed. You must use Design View to accomplish this.
28. Click the View tool down-arrow and select Design View. The report
displays in Design view.
29. Position the cursor over the bottom-right corner of the report grid. A
four-headed resizing arrow appears.
University Information Technology Training & Documentation Department
63
Doing More with Access 2007: Adv. Queries & Reports
30. Drag the grid to the left (to about the 5 ½ ” mark). The grid is resized.
31. To view the report adjustments, click the View tool down-arrow and
select Report View. The report displays in Report view.
This report is not spanning the whole width of the page, but changes could be
made, such as increasing font size and the column widths, so that it would span
the whole page width.
A DDING A G RAPHIC TO A R EPORT
A graphic is a picture or illustration that can be added to a report. Graphics
available to you include clip art, images from files, scanned pictures, an object
that you create by drawing, and the like. Graphics can spice up a report, draw
the reader's attention, or easily convey a feeling or mood.
We will open up some room in the Report Header to accommodate the graphic.
1. Return to Design View.
2. Position your cursor over the horizontal light blue Page Header bar
so that the cursor becomes a double-headed vertical sizing arrow.
3. Click and drag the Page Header bar down to the 2-inch mark on the
vertical ruler. This will open up the Report Header to accommodate the
graphic.
University Information Technology Training & Documentation Department
64
Doing More with Access 2007: Adv. Queries & Reports
Note that the report is only one page.
To insert an image:
4. On the Report Design Tools, Design tab, in the Controls group, click the
Image tool (sun over the mountains).
The cursor changes shape.
5. Move your cursor that is now a plus sign and the sun over the mountains
image into the Report Header area and click in the Report Header area.
The Insert Picture window opens.
6. From the Insert Picture window browse to the class files and select
aquarium.wmf.
7. Click OK. The graphic is inserted into the report header area.
The graphic is large so we will resize it.
8. Click and drag one of the corner sizing handles to resize the
aquarium to about an inch in height and move it to the left side of the
page header area.
9. Preview the report.
University Information Technology Training & Documentation Department
65
Doing More with Access 2007: Adv. Queries & Reports
A DDING A C HART TO A R EPORT
A chart is a graphic representation of data. Charts can allow the viewer to
quickly understand data that may be difficult to understand in a typical report or
printout.
We'll enhance the report by adding a simple pie chart that will reflect the value of
our types of pets.
1. Click the View tool down-arrow and select Design View. The report
displays in Design view.
2. On the Report Design Tools, Design tab, in the Controls group, click the
Insert Chart tool.
The cursor changes shape to a crosshair with a
small column chart beside it.
3. Click in the Report Header area to the right of the aquarium graphic.
The first step of the Chart Wizard opens.
4. In the first step of the Chart Wizard, select the tblPets table. The chart
will be based on this table’s data.
5. Click Next. The next step of the Chart Wizard displays.
6. In the Available fields list, select the fields Type and Value and move
them into the Fields for Chart area. The chart will use these two fields.
7. Click Next. The next step of the Chart Wizard displays.
You may choose from 20 different chart types.
8. In the last row, select the 3-D Pie Chart
.
9. Click Next. The next step of the Chart Wizard displays.
This step allows you to layout the chart data so that it makes sense. A pie chart
reflects the relationship of the parts to the whole so we'll accept the default. We
chose a pie chart for this reason.
10. In the upper left, click the Preview Chart button
a preview of how the chart will look.
to see
11. Click Close. The Sample Preview closes.
University Information Technology Training & Documentation Department
66
Doing More with Access 2007: Adv. Queries & Reports
12. Click Next. The next step of the Chart Wizard displays.
Our chart will not change from record to record.
13. Click the down-arrows in both fields and select <No Field> or you
could just remove PetID from both fields.
14. Click Next. The last step of the Chart Wizard displays.
15. In the "What title would you like for your chart?" step, accept the default
title “tblPets.” Also accept the default for the legend, "Yes, display a
legend."
16. Click Finish. The chart appears in the report header. Don't be thrown
off by the East, West, North legend. When you toggle into Print Preview,
you will see live data reflected.
17. Preview the report to see the results.
Additionally, if you want to adjust other components of the pie chart, such as
remove the tblPets title, you may do so.
To remove the tblPets title:
1. Click the View tool down-arrow and select Design View. The report
displays in Design view.
2. Double-click the chart. The embedded MS Graph Chart opens.
3. Click the title. Sizing handles appear around the title.
University Information Technology Training & Documentation Department
67
Doing More with Access 2007: Adv. Queries & Reports
4. Press Delete. The title is removed.
If for some reason the entire chart is deleted, on the Quick Access toolbar,
click the Undo tool.
5. Click away from the graph. MS Graph closes.
6. Save your work.
To add a “Run date” label to the page footer:
1. Click the View tool down-arrow and select Design View. The report
displays in Design view.
2. On the Report Design Tools, Design tab, in the Controls group, click the
Label tool. The cursor changes shape to a crosshair with a small letter A
beside it.
3. In the Page Footer area, just above the date control, click and drag to
draw a rectangle that will hold the text label.
4. Type “Run date:”
University Information Technology Training & Documentation Department
68
Doing More with Access 2007: Adv. Queries & Reports
5. Click away from the label. The Run date label is deselected.
6. Click the Text Box tool and click in the Page Footer area.
7. Type =date() and align the Run date: label with the date text box.
8. Preview the report to see the results.
9. Return to Design view if you need to make any further adjustments.
10. Save your work.
S ORTING AND G ROUPING R EPORT D ATA
The Report Wizard provides a report that will automatically create groups and
totals for you during the design phase. Access also offers additional sorting and
grouping options. Rarely do you want to see data in the same order that it was
entered. Most likely, you want to see the records sorted on the basis of one or
more fields. Although the Wizard gives you the opportunity to group and sort
fields, you may decide to change the sort order for a report.
You can sort and group reports by using the Group & Sort button on the Design
tab.
To activate the Group & Sort options:
1. Click the View tool down-arrow and select Design View. The report
displays in Design view.
2. On the Report Design Tools, Design tab, in the Grouping & Totals group,
click the Group & Sort tool. The Group, Sort, and Total pane displays at
the bottom of the Report.
University Information Technology Training & Documentation Department
69
Doing More with Access 2007: Adv. Queries & Reports
The Pane reflects a hierarchical view of the existing grouping by Animal
and sorting by Type fields.
When a Group or Sort order is present in a report, Access creates an Action Bar
in the Group, Sort, and Total pane. Each Action Bar has a series of settings that
give you more control over how the action is performed when the report renders.
Group action bar:
Sort action bar:
By default, Access shows the basic settings pertaining to the action. Each Action
bar starts with the field and the order. Each item is followed with a drop down
arrow which displays a drop-down list of additional options.
The
button expands the Action Bar to display additional control for adding
Totals, Headers, and Footers.
The sort order is changed by using the Move Up
located at the end of each order bar.
•
and Move Down
tools
Try some of the sorting and grouping options.
When the Action Bar is collapsed or the Grouping pane is closed, all current
settings are retained.
If you find that you no longer require an action in the Group, Sort, and Total
pane, click the
(Delete) located at the end of the Action Bar and the grouping
or sorting will be removed from the report.
University Information Technology Training & Documentation Department
70