Vous êtes sur la page 1sur 34

Microsoft Access 2007

Module 2

http://pds.hccfl.edu/pds
Microsoft Access 2007:
Module 2
August 2007

©2007 Hillsborough Community College - Professional Development and Web Services


Hillsborough Community College - Professional Development and Web Services

The material contained in this training material is copyrighted ©2007 Hillsborough


Community College Department of Professional Development and Web Services and
may not be reproduced without express, written permission. Other trademarks, trade
names, logos, designs, brand names, and product services mentioned in this publica-
tion may be trademarks or registered trademarks of third parties.
Microsoft Access 2007 - Module II

Table of Contents
Objectives. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Import a Table from Excel. . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Export an Access Table to Excel. . . . . . . . . . . . . . . . . . . . . . . 5
Create a Query . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Query
Sort. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Show. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Text Data Criteria . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Wildcards. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Field Not in Result. . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Number. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Comparison . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Comparison And. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Comparison Or. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Aggregate Functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Count . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Avg (Average). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Parameters and the Between Operator. . . . . . . . . . . . . . . . . 21
Report Wizard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Modify a Report. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Insert Images into a Form or Report. . . . . . . . . . . . . . . . . . . 26
Resize Images in a Form or Report. . . . . . . . . . . . . . . . . . . . 27

i
Microsoft Access 2007 - Module II

Objectives
At the end of this training session you will be able to:
1. Import a table from Excel;
2. Export an Access table to Excel;
3. Create a query;
4. Sort fields in a query;
5. Show fields in a query;
6. Run a query using wildcards;
7. Run a query for fields not in result;
8. Run a query for a number value;
9. Run a query using the comparison criteria “And”;
10. Run a query using the comparison criteria “Or”;
11. Understand the purpose of Aggregate Functions;
12. Create and run a query using count;
13. Create and run a query using average;
14. Create and run a query using the parameter between;
15. Insert and resize a graphic/image;
16. Create and Modify a Report.


Hillsborough Community College - Professional Development and Web Services


Microsoft Access 2007 - Module II

Import a Table From Excel


Access and Excel work well together. It is
quite simple to import data from an already
existing Excel spreadsheet.

In this example, we are using the files 1


located on your computer’s desktop, in the
PDWS folder.

1. Open this module’s Access 2007 file.


3
e.g. Desktop > PDWS folder >Access > Access
II > Access2007_M2.accdb
Under the External Data tab>Import group, 2
click on Excel.
2. After the Get External Data dialog box
appears, click on Import the source data into
a new table in the current database.
Other options are to append the new records to a
table or link the Excel spreadsheet to the Access
database. If you choose to append the records 6
to a table, make sure the fields and data types
match with the existing data.
5
3. Click on the Browse button and select the file to
import.
e.g. Desktop > PDWS folder >Access > Access
II > Employee_Add.xlsx
4. Click OK.
5. Select which worksheet or range to import by
clicking on the Show Worksheets or Show
Named Ranges radio button.

e.g. Show Worksheets


7
6. Select the sheet or sheet range to import and
click on Next.
e.g. Sheet1
7. Add a check mark by clicking on the First Row
Contains Column Headings and click on Next.
Adding this check mark specifies that the first
row contains a column heading.


Hillsborough Community College - Professional Development and Web Services

8. You can specify information about the


spreadsheet fields on this screen, such as data
type. You can even specify if you do not want to
import a certain field. These specifications are 8
set in the Field Options area.
In this example, we are going to import all
fields.
9. Click Next.
10. Choose the appropriate primary key setting and
click on Next. 9
In this example the ID is the primary key;
however, Access can choose a primary key. Also
you can choose a primary key or choose not to
have any primary key.
Select Choose my own primary key and ID
from the drop-down list. 10
11. Type a name for the table and click on Finish.
e.g. tblEmployeeAddresses
12. If you will be importing a file repeatedly, Access
gives you an option to save the import steps.
For this example, do not check to Save import
steps and click on the Close button.
13. tblEmployeeAddresses now appears in the left
pane, under Tables.

11
13

12


Microsoft Access 2007 - Module II

Export an Access Table to


Excel
Any database table can be exported, in a

2
variety of formats. In this example, we are
going to export to Excel.

1. In the Navigation Pane, select the object to 1


export,
e.g. tblEmpInfo
2. In the External Data tab>Export group, select
Excel.
3. Click the Browse button to select a destination 3
for the exported file.
4. Select an appropriate file format. If you need
4
to share this file with people that do not have
Excel 2007, choose Microsoft Excel 97-2003.
If that is not a concern, select Excel Workbook. 5
5. Specify the appropriate export options. Add a
checkmark to Export data with formatting
6
and layout. You can also select the option
Open the destination file after the export
operation is complete, if you would like to

7
preview the exported file.
6. Click on OK.
7. If you elected to Open the destination file
after the export operation is complete, Excel
will open with the new exported file displayed.
8. Save the export steps, if this is a regularly
occurring export and click Close.


Hillsborough Community College - Professional Development and Web Services

Create a Query
A query allows for table inquiries. A query
can change, delete, add, and arrange 1
data in tables. Queries also aid gathering
information for forms and reports. With 2
a query you can ask questions and set
parameters.

1. Select the Create tab. 3


2. In the Other group, select Query Wizard.
3. Select Simple Query Wizard and click OK.
4. Under Tables/Queries, click on the down arrow
and select the tables and/or queries to create and
run a new query.

e.g. tblEmpInfo.

5. In the Available Fields list, select the table's


field(s) to add to the query.
In this example, all the fields are used; therefore,
click on the double-headed arrow icon to move
all the items (fields) to the Selected Fields list.
6. Click Next.

6

Microsoft Access 2007 - Module II

7. Select a Detail or Summary.


e.g. Detail
8. Click on Next. 7
9. Type a title for the query, such as
qryEmployeeComp.
10. Click on either the Open the query to view
information radio button or the Modify the
query design radio button.
e.g. Modify the query design 8
11. Click Finish.
12. The qryEmployeeComp query is now
displayed in Design View.

10
11

12


Hillsborough Community College - Professional Development and Web Services

Query in Design View: Sort


Sorting information can be a valuable
tool when dealing with large amounts of
information or when simply organizing
information (fields). More than one field can
be sorted; however, the field farthest to the
left is given priority when sorting.

Fields can be sorted by:


Ascending
Descending 1
Not Sorted

In this example, the LastName field is 2


sorted in ascending order.

1. While in Design View, click in the blank box


next to Sort, under Lastname; a down arrow
appears.
3
2. Select the sort option.
e.g. Ascending
3. In the Query Tools/Design tab>Results group,
click the Run button to activate the query and
see your results.
4. Go back to Design View to edit your query.


Microsoft Access 2007 - Module II

Query in Design View: Show


The Show option displays or hides fields in
a query or form.

In this example, some fields will be hidden.

1. While in Design View, uncheck the show box


for Exempt, Zip Code and Street.

To show fields in a query’s results, add a

1
check to each field name’s Show checkbox.
To hide fields in a query’s results, remove
the check in the field name’s Show
checkbox.

2. Click the Run button to see your query results.


Notice that the Exempt, Zip Code and Street
fields are not being shown.

3. Select Design View to make more adjustments


to the query design.


Hillsborough Community College - Professional Development and Web Services

Query: Text Data Criteria


Text Data is data in fields that are in text
format. Such examples include but are not
limited to names, addresses, employee
number, location, etc.

In this example, employees that are exempt


are queried.

1. In the Criteria section under Exempt, type the


text data criteria. 2
e.g. Yes
1

2. Check the Show box for Exempt, to show this
field in the results.
3. In the Query Tools/Design tab>Results group,
click the Run button.
4. The results of the query now display all
employees that are Exempt. 3

Activity
Run a query looking for employees who live in
Temple Terrace. How many HCC employees live in
Temple Terrace?

10
Microsoft Access 2007 - Module II

Query Criteria: Wildcards


In this example, the last name of an em-
ployee with the letter M is queried.
2
1. Go back to Design View. In the Criteria
section under LastName, type the text data
criteria.
e.g. M*
2. Click on the Run button.
3. The results of a query now display all
employees with a last name that begins with the
letter M.

Wildcards are useful in Access to serve as


a character or blending of characters.

There are two types of wildcards in Access


* (asterisk)
1
? (question mark)

The * wildcard symbolizes any compilation


of characters. Therefore, mi* stands
for the letters mi, followed by any letter 3
combination.

The ? wildcard symbolizes any defined letter.


As a result, B?rt operates as the letter,
B, followed by any single letter, r, and t.
Appropriately, B?rt can mean Bert or Burt.

Activity
Run a query looking for employees working at a cam-
pus with the letter D. How many employees work at a
campus with the letter D?

How would you run a query for employees working


at District? How many employees work at District?

11
Hillsborough Community College - Professional Development and Web Services

Query Criteria: Field Not in


Result

Field Not in Result is a query where


3
criteria for a specific field do not need to
appear in the outcome of the final query. In
this example, the last name, first name, and
middle initial are necessary. However, the
campus does not need to appear. Therefore,
a query with only the names of the
employees working at the Brandon campus
is required.

1. In Design View, uncheck the items to be hidden.


e.g. Campus
2. Type criterion in the Criteria section, under
Campus. 1
e.g. BR
2
3. Click on the Run button.
4. The results of the query now display all
employees at the Brandon campus.

12
Microsoft Access 2007 - Module II

Query Criteria: Number

Using a number in a criteria is useful when


information from a data field that consists
of numbers is required. A dollar sign or
decimal point is not required in the criterion.

In this example, the names, campuses, and


the salary of employees earning $39,800.00
are needed.

1. In Design View, type criterion in the Criteria


section. For example, under Salary, type 39800.
Do not type in the dollar sign or the decimal 1
point. Uncheck unnecessary fields, such as
Street, City, State, ZipCode and Exempt.
2. Click on the Run button.
3. The results of the query now display all
employees whose salary is $39,800.00.
2

Activity
Run a query looking for employees earning $60,000.
How many employees are earning $60,000?

13
Hillsborough Community College - Professional Development and Web Services

Query Criteria: Comparison


Using a number in a criteria is useful when
information from a data field that consists
of numbers is required. A dollar sign or
decimal point is not required in the criterion.

In this example, the names, campuses, and


the salary of employees earning more than
$30,000.00 is needed.

1. In Design View, type criterion in the Criteria


section.
e.g. Under Salary, type >30000. Do not type in 1
the dollar sign or the decimal point.
2. Click on the Run button.
3. The results of the query now display all
employees earning more than $30,000.

Activity
Run a query looking for employees earning less than
$30000. How many employees are earning less than
$30,000?

14
Microsoft Access 2007 - Module II

Query Criteria: Comparison


AND
Using the AND criteria is appropriate when
information is needed from multiple fields.

AND conditions must appear on the same


criteria line, for example, the names of
employees earning more than $30,000.00
at the Dale Mabry campus.

1. In Design View, type criterion in the Criteria


section.
e.g. Under Salary, type >30000. Do not type in
the dollar sign or the decimal point.
2 1
2. Type the AND criterion.
e.g. Under Campus, type DM.
3. Click on the Run button.
4. The results of the query now display all
employees earning more than $30,000 at the 3
Dale Mabry campus.

Since the two conditions are on the same

4
line, each one must be true.

Activity
Run a query looking for employees working at the
Ybor campus and who are exempt. How many em-
ployees are working at the Ybor campus and are
exempt?

15
Hillsborough Community College - Professional Development and Web Services

Query Criteria:
Comparison OR
Using the OR criteria is applicable when in- 2 1
formation is needed from multiple fields.

OR conditions must appear on the separate


lines. 4
In this example, the names of employees
earning less than $30,000.00 or with the
last name beginning with the letter M are
required.

1. Type criterion in the Criteria section.


Under Salary, type <30000. Do not type in the
dollar sign or the decimal point.
2. Type the OR criterion.
Under Last Name, type M* on a separate line.
3. Click on the Run button.
4. The results of the query now display all
employees earning less than $30,000 or
employees with a last name beginning with the
letter M.

Since the two conditions are on separate


lines, at least one condition must be true.

Activity
Run a query looking for employees working at the
Ybor (YB) campus or the Plant City (PC) campus.

16
Microsoft Access 2007 - Module II

Aggregate Functions
Aggregate functions within Access allows
the user to carry out simple mathematical
operations within a query. Aggregate
functions (operations) include sum,
average, minimum, maximum, count,
standard deviation and variance. These
functions can be accessed by selecting the
Totals button on the query design toolbar
or typing the aggregate function in the Total
row of the Design grid.

Aggregate Function Description


Sum Determines the sum of field values. Supports the
following data types: AutoNumber, Currency, Date/
Time and Number.

Avg Calculates the average of field values. Supports the


following data types: AutoNumber, Currency, Date/
Time and Number.

Min Determines the lowest field value. Supports the


following data types: AutoNumber, Currency, Date/
Time, Number and Text.

Max Determines the highest field value. Supports the


following data types: AutoNumber, Currency, Date/
Time and Number.

Count Determines the number of records in a field.


Supports the following data types: AutoNumber,
Currency, Date/Time, Memo, Number, OLE Object,
Text and Yes/No.

StDev Calculates the standard deviation of a field value.


Supports the following data types: Currency or
Number.

Var Calculates the statistical variances of a field.


Supports the following data type: Currency.

17
Hillsborough Community College - Professional Development and Web Services

Query: Using the Aggregate


Function Count
Using the aggregate function Count is
useful when a simple count or tally of
information is required.
2
1. In the Create tab>Other group, select Query
Design.
2. Select the tables and/or queries to show and
click Add.
e.g. tblEmpInfo
3. Click Close. 3
4. Double click on a field name from the table or
query twice to appear in the query design grid.
e.g. Campus.

18
Microsoft Access 2007 - Module II

5. In the Query Tools/Design tab>Show/Hide


group, click on the Totals button.
6. The Total row now appears in the design grid
between Table and Sort.
5
7. Select the aggregate function on the second
Campus field
e.g. Count.

8. Click on the Run button.


9. Result of query using the aggregate function
Count.
10. Save the query as qryCntCampus.

8
Activity
Create a query for gender using the aggregate func-
tion Count. Save the query as qryCntGender

How many are males? How many are females?

How could using the aggregate function Count be 9


useful to you?

19
Hillsborough Community College - Professional Development and Web Services

Query: Using the Aggregate


Function Avg
Using the aggregate function Avg
(average) is useful when an average of 2
information is required.

In this example, we are determining the


average salary by campus.

1. Under the Create tab>Other group, select


Query Design.
2. Select the tables and/or queries to show and
click Add. 3
e.g. tblEmpInfo
3. Click Close.
4. Double click on the field names from the table
to appear in the Field design grid.
e.g. Campus and Salary.

5. Click on the Totals button. The Total row 5


now appears in the design grid between Table
and Sort.
6. Select the aggregate function on the second field
and click on the Run button.
e.g. Avg.
7. Result of query using the aggregate function 4
Average.
8. Save the query as qryAvgSalaryCampus. 6

Activity
Create a query for the average salary by city using the
aggregate function Avg. Save the query as 7
qryAvgSalaryCity.

Which city has the highest average salary?

How could using the aggregate function Avg be use-


ful to you?

20
Microsoft Access 2007 - Module II

Query: Using Parameters and the


Between Operator
Creating a parameter query allows you to
search for information in fields. However, for
the parameters to function, you will have 1
to enter the criteria when prompted by the
parameter dialog box.

In this example, we are determining the


names of the people whose start date is
2
between 1/01/1980 and 12/31/1999.

1. Under the Create tab>Other group, select


Query Design.
2. Select the tables and/or queries to show and
click Add.
e.g. tblEmpInfo
3
3. Click Close.
4. Double click on the field names from the table
to appear in the Field design grid.
e.g. FirstName, LastName, and StartDate.
5. Under StartDate Criteria type the following:
Between [Beginning Start Date] And [Ending
Start Date].

21
Hillsborough Community College - Professional Development and Web Services

6. Click on the Run button and enter the


following parameters Beginning Start Date:
1/01/1980 and Ending Start Date: 12/31/1999.
7. Result of query using the parameter Between.
8. Save the query as qryBtwnStartDate.
6

Activity
Create a query using parameters. The query will show
the names of people, salary and campus. Save the
query as qryBtwSalaryCampus.

Show how many people make between $30,000 and


$40,000 and at which campus he/she works.

What are the results for each campus?

22
Microsoft Access 2007 - Module II

Create a Report: Report


Wizard
Report Wizard is easy to use and allows
for the design, development, printing, and
print preview of information such as labels,
lists, form letters, invoices, summaries, 1
display charts, etc. The user can personalize
reports by adding a logo or picture,
organizing headers, footers and sorting
columns.

In this example, the names of employees


earning more than $30,000.00 or with the 2
last name beginning with the letter M are
required. Adjust the qryEmployeeComp
query, if necessary.

1. In the All Access Objects pane, select


the object that you would like to use for 3
creating the report. For example, select
qryEmployeeComp.
2. Under the Create tab>Reports group, select
Report Wizard.
3. Make sure the correct table or query is selected.
Add Available Fields to Selected Fields and
click on Next.
In this example, qryEmployeeComp should be
selected and add all available fields.
4. Add any grouping levels; however, in this
example do not add any. Therefore, click on
Next.

23
Hillsborough Community College - Professional Development and Web Services

5. Sort records, up to four fields in ascending or


descending order, and click on Next. In this
example, the fields LastName and FirstName,
are sorted in ascending order.
6. Choose a report layout and orientation and click 5
on Next.
e.g. Tabular layout and Landscape orientation
7. Choose a report style and click on Next.
e.g. Access 2007
8. Type in a report title, preview the report, or
modify the report’s design and click on Finish.
e.g. rptEmployeeInfo
9. The Employee Information report now appears.

9 7

24
Microsoft Access 2007 - Module II

Modify a Report
Design View and Layout View allow for
the modification and customizing of reports
by adding a logo or picture, organizing
headers, footers, and sorting columns.

In this example, the Employee Information


report is modified. 1
1. In the Home tab>Views group, select View >
Design View to change to Design View.
2. The report now appears in Design View.
3. To change the font, highlight the text box, then
make your font selection. For example, click 4
on the Last Name label text box and choose a
larger font size. Also change the alignment to
Center.
4. Select Report View see the changes.
5. Report changes are viewable.

3
To move report objects around, click on an
object and drag it to the new location, while
you are in Design View or Layout View.
You can also resize and delete columns.

Activity
Modify rptEmployeeInfo by changing the font, size
and color. Change the report header title to HCC
Employee Information. Delete unnecessary columns
to save space.

25
Hillsborough Community College - Professional Development and Web Services

1
Insert a Graphic/Image
Personalize forms and reports by adding a
company logo or another graphic. To insert
a graphic into a form or report, you can be
in Design View or Layout View. In this
example, we’ll use Design View. 2
1. In the Report Design Tools/Design
tab>Control group, click Image.
2. Take the image pointer and click and hold, then 3
draw a rectangle to the approximate size of the
graphic in the location where the image will
appear. Release mouse button after the Image
box is drawn.
In this example, the HCC logo is added to the
report header.
3. After the Insert Picture dialog box appears,
locate the file and click on OK.
e.g. Desktop > PDWS Folder > Access II>
HCCLogo. 4
4. Resize graphic with sizing handles.

26
Microsoft Access 2007 - Module II

Resize Image/Graphic
Sometimes after an image is placed on a
form or report, it does not fit properly in its
box. Below are the steps to resize an image 1
without resizing the box entirely.

1. Select the image.


2. Right click on the mouse and click on
Properties.
3. Click on the Format tab.
4. Point to and click on Size Mode down arrow
and choose Stretch.
5. The image now fits in the box.

Activity
Insert an image into your report and resize the image
using the Resize Image/Graphic steps.
5

27
Hillsborough Community College - Professional Development and Web Services

28

Vous aimerez peut-être aussi