Sei sulla pagina 1di 22

Intermediate Microsoft Access 2000

Academic Technology Support


California State University, Los Angeles
Version 3.06

Spring 2002

Contents
Intermediate Microsoft Access 2000 ........................................................................................... 2
Downloading a Data File .............................................................................................................. 2
Creating Relationships Between Tables...................................................................................... 3
Creating a Relationship............................................................................................................. 3
Setting Referential Integrity...................................................................................................... 4
Using a Subdatasheet ................................................................................................................ 5
Adding Additional Tables to the Relationships ........................................................................ 5
Analyzing Tables........................................................................................................................... 7
Using the Table Analyzer Wizard............................................................................................. 7
Action Queries............................................................................................................................. 11
Creating an Action Query ....................................................................................................... 12
Designing Advanced Queries ..................................................................................................... 12
Creating a Function Query...................................................................................................... 12
Advanced Query Wizard............................................................................................................ 13
Crosstab Query Wizard........................................................................................................... 13
Find Duplicates Wizard ......................................................................................................... 13
Find Unmatched Wizard ......................................................................................................... 14
Creating a Chart ......................................................................................................................... 14
Using the Chart Wizard ......................................................................................................... 14
Importing and Exporting Data .................................................................................................. 16
Importing an External Data ................................................................................................... 16
Importing an Excel File ........................................................................................................ 17
Exporting a Database Object ................................................................................................ 20
Exporting a Data to External Formats .................................................................................. 21
Exporting Objects to Other Access Database ....................................................................... 22

For additional written instructional guides, visit us @ http://www.calstatela.edu/handouts

Intermediate Microsoft Access 2000


This handout is a continuation to the Introduction to Access 2000. The introduction handouts
cover the basic of the Access program including creating a table, setting field properties, and
entering the data into the table. If you want to obtain a copy, you can go online and log on to
http://www.calstatela.edu/handouts.

In this part, you will learn how to relate tables, and how to create advanced query features,
forms, and reports. You can create relationships between the tables you have created. In
addition, you can create other objects, such as query, form, and report. Once your information is
stored, it is important to be able to display it from the tables using relationships, queries, forms,
and reports.

Downloading a Data File


You can continue to use the existing file that you used for the Introduction to Microsoft Access
handout. If you do not have that file, you will need to download the atstrainingmember.mdb file
following the instructions below. Once you download the sample data files, you can use it to
perform the procedures described in this handout.
Note:
The diagrams in this handout were captured using files on which the exercises from the
Introduction handout were performed. If you are using newly downloaded sample files, the
resulting tables you encounter may be slightly different from the tables shown in this handout.
To download files from the Internet:
1. Double click on the Internet Explorer icon on your desktop.
2. Type the following address in the website Address bar to download the file:
[ftp://ftp.calstatela.edu/pub/ats/atstrainingmembers.mdb] and press the [Enter] key.
3. The File Download dialog box opens. Select the Save this file to disk option button, and
click on the OK button, as shown in Figure 1.

Figure 1 File Download Dialog Box

4. The Save As dialog box opens. Select 3 Floppy [A:] (or Z:) from the Save in drop
down list.
5. In the File name: and Save as type: text boxes, keep the default file name.
6. Click on the Save button.

Intermediate Microsoft Access 2000 - 2

Creating Relationships Between Tables


You can relate tables that contain similar information or fields in order to access and coordinate
data more efficiently. By relating tables, you can avoid entering duplicate data in various tables,
and you can efficiently manage the data. For example, if you create a table consisting of student
ID numbers, names, addresses, telephone numbers, class ID numbers, class times, and faculty
names, you will need to enter the same students information whenever the students enroll
different classes. However, if you create two different tables and relate those two tables, you can
avoid entering duplicate students information whenever the students enroll.
Creating a Relationship
There are three types of relationships: one-to-one, one-to-many, and many-to-many
relationships. Because one-to-many relationship is the most useful and popular relationship, we
will practice a one-to-many relationship in this exercise. Assume that you created two tables,
Students table and Classes table, and entered student information into the Students table and
enter class information into the Classes table. You will need to relate these two tables to create a
relationship. Start by selecting the primary key (SSN field) from the primary table (Students)
and drag it to the related table (Classes) to create a relationship. Access prevents duplicate
entries when using the primary key from the primary table.
To create a relationship between tables:
1. Click on the Relationships button
on
the toolbar. The Relationships window
opens with the Show Table dialog box (see
Figure 2).
2. Select the Students table.
3. Click on the Add button.
4. Select the Classes table.
5. Click on the Add button.
6. Click on the Close button. The Students
and Classes table field lists will open in the
Relationships window (see Figure 2.1).
7. Click on the SSN field in the Students
table field list, and drag it to the SSN field
in the Classes table field list. The Edit
Relationships dialog box will appear
(Figure 2.2).
8. Click on the Create button, the Edit
Relationships dialog box closes, and the
created relationship will be represented by
a join line as shown in Figure 2.3.
9. Click on the Save button on the toolbar.
10. Close the Relationships window.

Figure 2 Show Table Dialog Box

Figure 2.1 Setting Relationships


Between Tables

Intermediate Microsoft Access 2000 - 3

Figure 2.2 Edit Relationships Dialog Box

Figure 2.3 After Setting a


Relationship

Note:
When you relate tables, the tables are related by the join fields. In this exercise, SSN
field in the Students table and SSN field in the Classes table are the join fields. The join
fields in both tables must have the same data types, which means, if SSN field in the
Students table is a text field, then the SSN field in the Classes table must be a text field
as well. However, it is not necessary that the join fields have the same field name.
To remove a relationship, right click on the join line to bring up your shortcut menu and
select Delete.
Setting Referential Integrity
When you create a relationship between two tables, you can set referential integrity. Setting
referential integrity is not mandatory, but it is strongly recommended when creating a
relationship. Referential integrity makes sure that the relationship is valid, which means, it
checks if the joined field in the primary table is the primary key, if the joined fields in both tables
are related, and if they have the same data type and belong to the same database. When the
relationship is verified, Access displays the type of relationship on the joined line (see Figure
3.1). It also prevents accidental deletion or editing of data.
To use referential integrity:
on the Database toolbar.
1. Click on the Relationships button
2. If youve already created relationships between tables, double-click on the join line
between the table field lists (Figure 3). The Edit Relationships dialog box opens (see
Figure 2.2). If there is no relationship between two tables, establish the relationship first.

Join Line
Figure 3 Relationships Dialog Box

Intermediate Microsoft Access 2000 - 4

3. Click on the Enforce Referential Integrity check box.


4. Click on the OK button.
Note:
When the referential integrity is set, Access displays symbols above the joined line in the
Relationships window to indicate the type of relationship: one-to-one or one-to-many.
The number 1 above the joined line indicates one, while the mathematical symbol for
infinity indicates many (Figure 3.1).

Figure 3.1 Relationships with Referential Integrity

Using a Subdatasheet
Once you related two tables in a one-to-many relationship, you can use a subdatasheet that
allows you to see, edit, and enter records that are related to a record in one table.
To use a subdatasheet:
1. Double click on the Students table in the Database window to open it. The Students
table opens in datasheet view (see Figure 4).
Note:
When Students table datasheet opens, notice the plus signs
to the left of the records.
These plus signs indicate that this datasheet has a subdatasheet. Because the Students
table is related to the Classes table, the subdatasheet is taken from Classes table.

Figure 4 Students Datasheet With Subdatasheet

2. Click on the plus sign


to the left of the record. The subdatasheet of Classes table will
appear (Figure 4.1), and the plus sign will turn into a minus sign .

Intermediate Microsoft Access 2000 - 5

Figure 4.1 Subdatasheet View

Note:
Figure 4.1 shows that David Kim has four class records, which means, he is currently
enrolled. You may notice that John Smith has no class record, which means, he is not
enrolled. The advantage of establishing relationships between tables is that you can enter
new data directly into a subdatasheet. For instance, if the student enrolls in a new class,
open the subdatasheet (Classes table) of the student and enter the information, such as
course ID, course titles, and day. Notice that you do not have to enter student
information, such as student name, student address, and phone number, into the Classes
table.
Adding Additional Tables to the Relationships
Once you have established relationships between two tables, you can add additional tables to the
relationships. For example, each class requires some textbook, sometimes more than one. You
can save all the information about the textbook in the Text table, and relate this table with
Classes table (Figure 5). The relationships between more than two tables work like cascades.
From Students table, you can open Classes table, and again, from Classes table, you can open
the Text table (Figure 5.1).

Figure 5 Adding Additional Table(s) to the Relationship

To add additional tables:


1. Open the Relationships window
2. Click on the Show Table
button from the Relationship toolbar.
3. Select the Text table and click on the Add button.
4. Click on Close button to close the Relationships window.
Intermediate Microsoft Access 2000 - 6

Figure 5.1 Multiple Subdatasheets View

Note:
Figure 5.1 shows that David Kim has four class records; BUS 101, CIS 410, Eng 102,
and ANTHRO 250. In addition, the class BUS 101 has two Text records, which means
this class requires two textbooks: Introduction to Business and Fundamental Business.

Analyzing Tables
In most cases, you can create many tables and be able to create relationships among these tables
when you design a database. However, sometimes you will find that your tables are not created
in the most efficient way. For example, you might have duplicate information in the same field.
In that case, you need to split the table into two or more related tables.
Using the Table Analyzer Wizard
Before you split a table, you will need to analyze the table to see if it is designed in the most
efficient way. The Table Analyzer Wizard checks the table to determine if the information is
duplicated in the fields across many records. If the table needs to be split, the Table Analyzer
Wizard splits the table and creates new ones, while leaving the original table intact. For
example, in Figure 6, the School table has duplicate information under Class ID, Course Title,
Day, and Time fields. So, we need to split this table into two tables.

Duplicate
Fields

Figure 6 Table With Duplicate Information

Intermediate Microsoft Access 2000 - 7

To use the Table Analyzer Wizard:


1. Select the table you want to analyze in the Database window and click on the Analyze
button
on the Database toolbar. The Table Analyzer Wizard: Looking At the
Problem dialog box opens (see Figure 6.1).

Figure 6.1 Table Analyzer Wizard: Looking At The Problem

2. Click on the Next Button. The Table Analyzer Wizard: Solving the Problem dialog
box opens (see Figure 6.2).

Figure 6.2 Table Analyzer Wizard: Solving the Problem

3. Click on the Next Button. The next Table Analyzer Wizard dialog box opens allowing
you to select the table you want to analyze (see Figure 6.3).

Intermediate Microsoft Access 2000 - 8

Figure 6.3 Table Analyzer Wizard: Selecting Table

4. Select the table you need to analyze, and click on the Next button. The next dialog box
opens (see Figure 6.4) to determine if you want the wizard to decide what fields go in
what tables.

Figure 6.4 Table Analyzer Wizard: Deciding What Fields Go in What Tables

5. Select the Yes, let the wizard decide option button, if necessary, and click on the Next
button. The next Table Analyzer Wizard dialog box opens (see Figure 6.5).

Intermediate Microsoft Access 2000 - 9

Figure 6.5 Table Analyzer Wizard: Naming New Tables

6. Rename Table1 and Table2.


a. Double-click on the Table1 title bar. The next Table Analyzer Wizard - Table
Name: dialog box opens (see Figure 6.6).

Figure 6.6 Table Analyzer Wizard: Naming Table1

b. Enter a name [Student] for Table1, and click on the OK button.


c. Enter a name [Class] for Table2, and click on the OK button
7. Click on the Next Button. The next dialog box opens (see Figure 6.7).
8. Select the field (Class ID in the Class table) that you want to set as the primary key
9. Click on the Set Unique Key button
at the top of the Table Analyzer Wizard
dialog box, then, click on the Next Button.

Figure 6.7 Table Analyzer Wizard: Selecting Primary Key

Intermediate Microsoft Access 2000 - 10

10. The last dialog box opens (see Figure 6.8). Click on the Finish button. The Table
Analyzer Wizard creates two new tables (Class and Student tables) from the School
table as shown in Figure 6.9.

Figure 6.8 Table Analyzer Wizard: Finishing Table Analyzer Wizard

Figure 6.9 Table Analyzer Wizard: New Tables Created

Action Queries
The term Action Query defines a query that does something more than simply selecting a
specific group of records. An action query modifies or creates table. You can use an action
query when you want to change a large amount of data in an existing table.
Intermediate Microsoft Access 2000 - 11

There are four types of action queries in Access: Make-table query, Update query, Append
query, and Delete query (see table 1 for description).
Table 1 - Action Query Description
Action Query Type
Description
Make-table query

Creates a new table containing the selected records

Update query

Updates the selected records in one or more tables


Adds the selected records to the end of one or more
tables

Append query
Delete query

Deletes the selected records from one or more tables

Creating an Action Query


Creating an action query is very similar to creating a selected query. You specify the fields for
the query and any criteria. Then, you specify an action query: Make-table query, Update
query, Append query, or Delete query (see Figure 7).

All action queries


commands are on the
Query menu.
Figure 7 - Query Menu

Designing Advanced Queries


Although the most basic and important feature of queries is to select specific records or fields
from the table and display them, there are more advanced features of queries, such as creating a
function query and a parameter query.
Creating a Function Query
Access allows you to group records by a selected field as well as apply a function that calculates
values in other fields in the query. For example, you can group records in a RecordSet by
Region and then apply the Sum function to find out how many Sales Reps are in each Region
(see Figure 8). See Table 2 for Function descriptions.
Once you select the Totals
command on the View menu,
a Total row is added to
the design grid. Then,
the insertion point
appears in the Total row
under the appropriate
field. Select the desired
function.
Figure 8 - Function Query Design Grid

Intermediate Microsoft Access 2000 - 12

Table 2 - Types of Function

Function

Description

Group By
Sum
Avg
Min
Max
Count

Organizes query results


Sums the values in the calculated field
Finds the average value of the calculated field
Finds the lowest value in the calculated field
Finds the highest value in the calculated field
Counts the number of records in the calculated field

Advanced Query Wizard


Access 2000 employs three advanced query wizards: Crosstab Query Wizard, Find
Duplicates Query Wizard, and Find Unmatched Query Wizard. You can select the advanced
query wizards from the New Query dialog box (see Figure 9).

Figure 9 - New Query Window

Crosstab Query Wizard


By using the Crosstab Query Wizard, you can calculate a sum, average, count, or other types
of value for data and group the value and display it in a spreadsheet format. You will need three
fields to create a Crosstab query. The first field displays its values as row headings for the
datasheet. The second field displays its values as column headings. The third field is the field on
which the calculation is performed (see Figure 10).
The field, Sales
Rep, displays its
values as column
headings.
The summary value field,
Qty, displays its value
in each cell intersected
by each column and each
row. For example, the
value, 22, is the value
of Qty for Prod ID, 106025 in Sales Rep, GEA.
Figure 10 - Crosstab Query

Find Duplicates Wizard


The Find Duplicates Query Wizard assists you in designing a query that displays duplicate
records in tables. The unnecessary duplicate records can then be deleted from the table. This
query can be used to group records with the same field values, such as finding all customers in a
particular city (see Figure 11).
Intermediate Microsoft Access 2000 - 13

These two
customers are
duplicate
records, and
one of them
needs to be
deleted.

Figure 11 - Find Duplicate Query

Be careful!
Although these two
customers have the
same store name,
they may not be
duplicate records
because they have
different contact
name and phone
number.

Find Unmatched Wizard


If you create relationships between tables, you may have the records that do not match any
records in a table that it is related to. The Find Unmatched Query Wizard assists you in
designing a query that finds these unmatched records (see Figure 12).

These 14 records are


unmatched records, which
means that these records
are found in a primary
table but not in a related
table.

Figure 12 - Find Unmatched Query

Creating a Chart
Charts allow you to represent information in a database graphically. You can enhance Forms
and Reports by adding graphics (charts), pictures, and other objects. The easiest way to create a
chart is to use the Chart Wizard. The Chart Wizard assists you in creating charts by leading
you through a series of dialog boxes that allow you to choose options for the chart.
Using the Chart Wizard
You can start the Chart Wizard from either the Forms object or the Reports object.
To create a chart:
1. Click on the Forms or Reports button
from the Objects bar in the Database
window, and then click on the New
button to open a New Form or Report
dialog box (see Figure 13).
2. Select Chart Wizard and select the
table or query on which you want to
base the chart from the drop-down list.
Then click on the OK button. The
Chart Wizard opens (see Figure 13.1)
Figure 13 - New Form Window

Intermediate Microsoft Access 2000 - 14

Figure 13.1 - Chart Wizard: Selecting Fields

3. Select the fields containing the data you want to display in the chart from the Available
Fields list box and move it to the Fields for Chart list box by clicking on the right arrow.
Click on the Next button. The next Chart Wizard dialog box opens (see Figure 13.2) to
select the chart type.

Figure 13.2 - Chart Wizard: Selecting Chart Type

4. Select the desired type of chart and click on the Next button. The next Chart Wizard
dialog box opens (see Figure 13.3).

Data Series box

Field buttons
Data Source box

Figure 13.3 - Chart Wizard: Selecting Data Source and Data Series

Intermediate Microsoft Access 2000 - 15

5. Select data source and data series and click on the Next button. The next dialog box
opens (see Figure 13.4).
Note:
When you create a chart by using the Chart Wizard, the Chart Wizard automatically
decides which field should be the data source and which field should be the data series.
You can switch the data source and data series by dragging the field button to the Data
Source box or Data Series box (see Figure 13.3).
6. Enter a name for the chart, and then click on the Finish button to create the chart (Figure
13.4). Figure 13.5 shows a chart created by the Chart Wizard.

Figure 13.4 - Chart Wizard: Naming Chart

Figure 13.5 Chart Made Using


Chart Wizard

Note:
After you create a chart, you can edit the chart by opening the Chart Object menu.
Highlight the chart and right click on the mouse. Select Open from the Chart Object
menu. You can change the chart type, such as: pie, bar, or column from the Chart Type
menu, and chart titles, legend, or data labels from the Chart Options menu in the Chart
menu.

Importing and Exporting Data


For the beginners of Access, it may seem to be a little difficult to open or save Access files in
different locations or file types. It is because there are other commands like Import and Export
in Access. For example, if you need to open a spreadsheet file in Access, you will need to use
the Import command, not the Open command.
Importing External Data
When dealing with a database in Access, you might need to use another Access database or other
program files, such as text files, spreadsheet files, or other database files. You can copy the
content from an external file into Access table by importing it. When importing an external file,
a Wizard opens to provide you step-by-step instructions to modify the external file if the
external file is not an Access database file.

Intermediate Microsoft Access 2000 - 16

Importing an Excel File


You can import other program files into an Access database. For example, suppose you need to
import data from an Excel worksheet (Figure 14) into a new table in the Access database.

Figure 14 - Excel Worksheet

To import data to Access:


(Before processing the following steps, make sure that you have at least one external file).
1. Select the File menu.
2. Select the Get External Data
command.
3. Select the Import option (Figure 14.1).
The Import dialog box opens (see
Figure 14.2).
4. Determine the file type to be imported.
For example, choose Microsoft Excel
Figure 14.1 - Opening Import
from the Files of type drop-down list
Dialog Box
(Figure 14.2).

Figure 14.2 - Import Dialog Box

Intermediate Microsoft Access 2000 - 17

5. Choose the file that you want to import and click on the Import button. The Import
Spreadsheet Wizard opens (see Figure 13.3).

Figure 14.3 - Import Spreadsheet Wizard Dialog Box: Selecting Worksheets

6. Choose the Show Worksheets option button if necessary, and click on the Next button.
The next Import Spreadsheet Wizard dialog box opens (see Figure 14.4)

Figure 14.4 - Import Spreadsheet Wizard: Assigning Column Headings

7. Click on the First Row Contains Column Headings check box if necessary, and click on
the Next button. The next Import Spreadsheet Wizard dialog box opens (see figure 14.5).
Note:
Import Wizard automatically assigns the format of a new table according to the format
of external files imported. For example, if you import data from an Excel worksheet file,
Import Wizard changes the columns of an Excel file into the fields of a new table and
the rows of an Excel file into the records of a new table. In addition, Wizard
automatically changes the first row of an Excel file into the field names of a new table.
However, some external files, such as text files, are not compatible with Access files in
terms of formatting. In that case, you will have one more step to fix the format of
external files. Fixing the format of external files is very simple. Just follow the step
offered by Import Wizard.
Intermediate Microsoft Access 2000 - 18

Figure 14.5 - Import Spreadsheet Wizard Window: Storing Data

8. Select the In a New Table option button if necessary, and click on the Next button. The
next Import Spreadsheet Wizard dialog box opens (see Figure 14.6).

Figure 14.6 - Import Spreadsheet Wizard: Changing Field Options

9. You can edit field options, such as field names, field indexing, or skipping specific fields.
For example, if you want to change a field name, click on that field, and type a new field
name in the Field Name text box under Field Options, and click on the Next button. The
next Import Spreadsheet Wizard dialog box opens (see Figure 14.7).

Intermediate Microsoft Access 2000 - 19

A primary key field


is inserted if you
select Let Access add
primary key option
button.

Figure 14.7 - Import Spreadsheet Wizard Window: Assigning Primary Key

10. Select the Let Access add primary key option button if necessary, and click on the Next
button. The next Wizard dialog box opens (see Figure 14.8).
11. Name the imported table and click on the Finish button. Figure 14.9 shows a new table
imported from an Excel spreadsheet file.

Figure 14.8 - Import Spreadsheet


Wizard Window: Naming Table

Figure 14.9 - New Table Imported From


Excel File

Exporting a Database Object


In other Microsoft programs, such as Excel or Word, you can use the Save as command when
you need to save the active file with a different file name, location, or file type. However, in
Access, you use Save as command only when you need to save an object with a different name
in the current database. If you want to save database objects with a different location or file type,
you need to use Export command, not the Save as command. The word, Export, can be
confusing because it sounds like moving something. However, when Access exports data from
an Access object to an external file or to other Access database files, Access does not move the
data, instead Access copies it to the target files. This means that you will still keep the original
Access object after exporting it.

Intermediate Microsoft Access 2000 - 20

Exporting Data to External Formats


You can copy data from an Access object into a new external file. For example, suppose that
you need to export Orders table (Figure 15) into a new Excel spreadsheet.

Figure 15 Table to be Exported

To export data:
1. In the Database window, select a table that you need to export by clicking on it.
2. On the File menu, click on the Export command. The Export Table dialog box opens
(see Figure 15.1).
3. Choose the file type from the Save as type drop-down list.
4. Click on the Save All button.

Figure 15.1 - Export Window

Note:
If you click the Save as type drop-down list, you will find the file types to which you can export
the Access objects. Access does not support all kinds of types or versions of external files to
which you can export. What can you do if you cannot find the formats or versions of the external
files to which you need to export? For example, suppose that you need to export a table in
Access to SPSS (Statistical Packages for Social Science) files type (*.sav) that Access does not
support. Here is a tip. Export a table to an Excel file, then, open the Excel file from SPSS
program. Excel files are the most flexible files, which means, you can open Excel files from
almost all types of software programs.
Intermediate Microsoft Access 2000 - 21

Figure 15.2 is an Excel spreadsheet exported from an Access table.

Figure 15.2 - Excel Spreadsheet Exported from Access Table

Exporting Objects to Other Access Database


You can export objects from the current database to another Access database. In most cases, you
can export the objects to another database when you need to save the objects in different
locations. For example, if you are working with database located in the C:\drive, but need to
save a table in the A:\drive, you will need to export the table to the database in the A:\drive.
To export a table from one database to another:
1. Select a table that you need to export by clicking on it.
2. Click on the File menu
3. Select the Export command.
4. Choose 3 Floppy (A:) from the Save in drop-down list.
5. Click on a database file and click on the Save button. The Export dialog box opens (see
Figure 16).

Figure 16 Export Dialog Box

6. Enter a new name for the exported table or keep the same one if desired.
7. Select the desired option button under Export Tables.
8. Click on the OK button.
The database in the A:\drive will have the table you exported from the database in the C:\drive.

Intermediate Microsoft Access 2000 - 22

Potrebbero piacerti anche