© Michael Brydon (brydon@unixg.ubc.ca)
Last update: 25-Aug-1997 Next Home Previous 1 o f 18
Access Tutorial 2: Tables
2.1 Introduction: The importance
of good table design
Tables are where data in a database is stored; consequently,
tables form the core of any database
application. In addition to basic data, Access permits
a large amount of domain knowledge (such as captions,
default values, constraints, etc.) to be stored at
the table level.
Extra time spent thinking about table design
can result in enormous time savings during
later stages of the project. Non-trivial changes
to tables and relationships become increasingly
difficult as the application grows in size
and complexity.
2.2 Learning objectives
How do I enter and edit data in the datasheet
view of a table?
How do I create a new table?
How do I set the primary key for a table?
How do I specify field properties such as the
input mask and caption?
Why won’t an autonumber field restart
counting at one?
What are the different types of keys?
2.3 Tutorial exercises
In this tutorial, you will learn to interact with existing
tables and design new tables.
Tutorial exercises 2. Tables
Next Home Previous 2 o f 18
2.3.1 Datasheet basics
• If you have not already done so, open the
univ0_v x.mdb database file from Tutorial 1.
• Open the Departments table. The important
elements of the datasheet view are shown in
Figure 2.1.
• Use the field selectors to adjust the width of the
DeptName field as shown in Figure 2.1.
• Add the Biology department (BIOL) to the table,
as shown in Figure 2.2.
• Delete the “Basket Weaving” record by clicking
on its record selector and pressing the Delete
key.
2.3.2 Creating a new table
In this section you will create and save a very basic
skeleton for table called Employees. This table
could be used to keep track of university employees
such as lecturers, department heads, departmental
secretaries, and so on.
• Return to the database window and create a new
table as shown in Figure 2.3.
• In the table design window shown in Figure 2.4,
type in the following information:
• Select File > Save from the main menu (or press
Control-S) and save the table under the name
Employees.
Field name Data type Description
(optional)
EmployeeID Text use employee
S.I.N.
FName Text First name
LName Text Last name
Phone Text
Salary Currency
Tutorial exercises 2. Tables
Next Home Previous 3 o f 18
FIGURE 2.1: The datasheet view of the Departments table.
The field names are shown in the “field
selectors” across the top of the columns.
The records are shown as rows.
The asterisk (*) indicates a
place holder for a new record. The grey boxes are “record selectors”.
The black triangle indicates the
“current record”.
The “navigation buttons” at the bottom of the window
indicate the current record number and allow you to go
directly to the first, previous, next, last, or new record.
You can temporarily sort the records
in a particular order by right-clicking
any of the field selectors.
Resize the DeptName column by clicking near
the column border and dragging the border to
the right.
Tutorial exercises 2. Tables
Next Home Previous 4 o f 18
FIGURE 2.2: Adding and saving a record to the table.
Add a new record by clicking in the DeptCode field
of the “new record” field (marked by the asterisk).
To permanently save the change to the
data, click on the record selector (note the
icon changes from a pencil to a triangle).
It is seldom necessary to
explicitly save new
records (or changes to
existing records) since
Access automatically
saves whenever you
move to another record,
close the table, quit
Access, etc.
Tutorial exercises 2. Tables
Next Home Previous 5 o f 18
FIGURE 2.3: Create a new table.
Click the New button to
create a new table.
Select “design view” (avoid using
the table wizard at this point).
Tutorial exercises 2. Tables
Next Home Previous 6 o f 18
FIGURE 2.4: Use the table design window to enter the field properties for the Employees table.
The “description” column allows
you to enter a short comment
about the field (this information
is not processed in any way by
Access).
Enter the field names and
data types for the five fields.
The “field properties” section
allows you to enter information
about the field and constraints on
the values for the field.
Tutorial exercises 2. Tables
Next Home Previous 7 o f 18
2.3.3 Specifying the primary key
Tables normally have a primary key that uniquely
identifies the records in the table. When you designate
a field as the primary key, Access will not allow
you to enter duplicate values into the field.
• Follow the steps in Figure 2.5 to set the primary
key of the table to EmployeeID.
2.3.4 Setting field properties
In this section, you will specify a number of field
properties for the EmployeeID field, as shown in
Figure 2.6.
• Since we are going to use the employees’ Social
Insurance Number (S.I.N.) to uniquely identify
them, set the Field Size property to 11 characters
(9 for numbers and 2 for separating spaces)
• Set the Input Mask property to the following:
000\ 000\ 000;0
• Set the Caption property to Employee ID
FIGURE 2.6: Set the field properties for the
EmployeeID field.
Tutorial exercises 2. Tables
Next Home Previous 8 o f 18
FIGURE 2.5: Set the primary key for the Employees table.
Click on the grey box beside the field (or
fields) that form the primary key.
Either click the key-shaped icon in the tool bar or
select Edit > Primary Key from the menu.
To select more than one field for use as the
primary key, hold down the Control key
while clicking on the grey boxes.
Discussion 2. Tables
Next Home Previous 9 o f 18
• Select View > Datasheet from the main menu to
switch to datasheet mode as shown in Figure 2.7.
Enter your own S.I.N. and observe the effect of
the input mask and caption on the EmployeeID
field.
• Select View > Table Design from the main menu
to return to design mode.
• Set the field properties for FName and LName
(note that Length and Caption are the only two
properties that are relevant for these two fields)
2.3.5 Using the input mask wizard
In this section, you will use the input mask wizard to
create a complex input mask for a standard field
type. You will also use the help system to learn more
about the meaning of the symbols used to create
input masks.
• Select the Phone field, move the cursor to the
input mask property, and click the button with
three small dots ( ) to invoke the input mask
wizard.
• Follow the instructions provided by the wizard as
shown in Figure 2.8.
• Press F1 while the cursor is still in the input mask
property. Scroll down the help window to find the
meaning of the “0”, “9”, “>” and “L” input mask
symbols.
2.4 Discussion
2.4.1 Key terminology
A key is one or more fields that uniquely determine
the identity of the real-world object that the record is
meant to represent. For example, there is a record in
the student information system that contains information
about you as a student. To ensure that the
record is associated with you and only you, it conDiscussion
2. Tables
Next Home Previous 10 o f 18
FIGURE 2.7: Observe the effect of the input mask and caption properties on the behavior of the
EmployeeID field during data entry
If a caption is specified, it replaces the
field name in the field selector.
Note that the input mask will not let you
type any characters other than numbers
from 0-9. In addition, the spaces between
the groups of numbers are added
automatically.
Input masks provide a relatively easy way to
avoid certain basic data input errors without
having to write complex error checking
programs. Note, however, that it is possible to
over-constrain a field so that users are unable to
enter legitimate values.
Try entering various characters and
numbers into the EmployeeID
field.
Press the Escape key when you are
done to clear the changes to the record.
Discussion 2. Tables
Next Home Previous 11 o f 18
FIGURE 2.8: Use the input mask wizard to create an input mask.
Select “phone
number” from the
list of commonlyused
field types.
In Step 2, you may
edit the input mask
(e.g., remove the
area code section).
The items in this
list depend on the
“international
settings” specified
for Windows (e.g.,
“Zip Code” may
show instead of
“Postal Code”).
Since the input mask controls how
the information in the field looks, it
is possible to save some disk space
by storing the data without the
extras symbols, spaces, etc. For the
size of system we are building,
however, this savings is negligible.
Discussion 2. Tables
Next Home Previous 12 o f 18
tains a field called “student number” that is guaranteed
to be unique.
The advantage of using student number as a key
instead of some other field—like “student name”—is
that there may be more than one person with the
same first and last name. The combination of student
name and address is probably unique (it is
improbable that two people with the same name will
at the same address) but using these two fields as a
key would be cumbersome.
Since the terminology of keys can be confusing, the
important terms are summarized below.
1. Primary key — The terms “key” and “primary
key” are often used interchangeably. Since there
may be more than one candidate key for an
application, the designer has to select one: this is
the primary key.
2. Concatenated key: The verb “concatenate”
means to join together in a series. A concatenated
key is made by joining together two or
more fields. Course numbers at UBC provide a
good example of a concatenated key made by
joining together two fields: DeptCode and
CrsNum. For example, department alone cannot
be the primary key since there are many courses
in each department (e.g., COMM 335, COMM
391). Similarly, course number cannot be used as
a key since there are many courses with the
same number in different departments (e.g.,
COMM 335, HIST 335, MATH 335). However,
department and course number together form a
concatenated key (there is only one COMM 335).
3. Foreign key: In a one-to-many relationship, a
foreign key is a field (or fields) in the “child”
record that uniquely identifies the correct “parent”
record. For example, DeptCode and CrsNum in
the Sections table are foreign keys since these
two keys taken together are the primary key of
Discussion 2. Tables
Next Home Previous 13 o f 18
the Courses table. Foreign keys are identified in
Access by creating relationships (see Tutorial 3).
2.4.2 Fields and field properties
2.4.2.1 Field names
Access places relatively few restrictions on field
names and thus it is possible to create long, descriptive
names for your fields. The problem is that you
have to type these field names when building queries,
macros, and programs. As such, a balance
should be struck between readability and ease of
typing. You are advised to use short-but-descriptive
field names with no spaces.
For example, in Section 2.3.2 you created a field
with name FName. However, you can use the caption
property to provide a longer, more descriptive label
such as First name. The net result is a field name
that is easy to type when programming and a field
caption that is easy to read when the data is viewed.
In addition, you can use the comment field in the
table design window to document the meaning of
field names.
It is strongly recommended that you avoid all
non-alphanumeric characters whenever you
name a field or database object. Although
Access will permit you to use names such as
Customer#, non-alphanumeric characters
(such as #, /, $, %, ~, @, etc.) may cause
undocumented problems later on.
2.4.2.2 Data types
The field's data type tells Access how to handle the
information in the field. For instance, if the data type
is date/time, then Access can perform date/time
arithmetic on information stored in the field. If the
same date is stored as text, however, Access treats
it just like any other string of characters. Normally,
Discussion 2. Tables
Next Home Previous 14 o f 18
the choice of data type is straightforward. However,
the following guidelines should be kept in mind:
1. Do not use a numeric data type unless you are
going to treat the field as a number (i.e., perform
mathematical operations on it). For instance, you
might be tempted to store a person's student
number as an integer. However, if the student
number starts with a zero, then the first digit is
dropped and you have to coerce Access into displaying
it. Similarly, a UBC course number (e.g.,
335) might be considered a number; however,
since courses like 439B have to accommodated,
a numeric data type for the course number field is
clearly inappropriate.
2. Access provides a special data type called Auto
Number (Counter in version 2.0). An autonumber/
counter is really a number of type Long Integer
that gets incremented by Access every time
a new record is added. As such, it is convenient
for use as a primary key when no other key is
provided or is immediately obvious.
Since an autonumber is really Long Integer
and since relationships can only be created
between fields with the same data type, it is
important to remember that if an autonumber
is used on the “one” side of a relationship, a
long integer must be used for the “many” side.
2.4.2.3 “Disappearing” numbers in
autonumber fields
If, during the process of testing your application, you
add and delete records from a table with an autonumber
key, you will notice that the deleted keys are
not reclaimed.
For instance, if you add records to your Customer
table (assuming that CustID is an autonumber), you
will have a series of CustID values: 1, 2, 3… If you
Discussion 2. Tables
Next Home Previous 15 o f 18
later delete customer 1 and 2, you will notice that
your list of customers now starts at 3.
Clearly, it would be impossible for Access to renumber
all the customers so the list started at 1. What
would happen, for instance, to all the printed
invoices with CustID = 2 on them? Would they refer
to the original customer 2 or the newly renumbered
customer 2?
The bottom line is this: once a key is
assigned, it should never be reused, even if
the entity to which it is assigned is subsequently
deleted. Thus, as far as you are concerned,
there is no way to get your customers
table to renumber from CustID = 1.
Of course, there is a long and complicated way to do
it, but since used an autonumber in the first place,
you do not care about the actual value of the key—
you just want it to be unique. In short, it makes absolutely
no difference whether the first customer in your
customers table is CustID = 1 or 534.
2.4.2.4 Input masks
An input mask is a means of restricting what the user
can type into the field. It provides a “template” which
tells Access what kind of information should be in
each space. For example, the input mask >LLLL
consists of two parts:
1. The right brace > ensures that every character
the user types is converted into upper case.
Thus, if the user types comm, it is automatically
converted to COMM.
2. The characters LLLL are place holders for letters
from A to Z with blank spaces not allowed. What
this means is that the user has to type in exactly
four letters. If she types in fewer than four or
types a character that is not within the A to Z
scope (e.g., &, 7, %), Access will display an error
message.
Discussion 2. Tables
Next Home Previous 16 o f 18
There are a large number of special symbols used
for the input mask templates. Since the meaning of
many of the symbols is not immediately obvious,
there is no requirement to remember the character
codes. Instead, simply place the cursor on the input
mask property and press F1 to get help. In addition,
the wizard can be used to provide a basic input mask
which can later be modified.
2.4.2.5 Input masks and literal values
To have the input mask automatically insert a character
(such as a space or a dash) in a field, use a
slash to indicate that the character following it is a literal.
For example, to create an input mask for local telephone
numbers (e.g., 822-6109), you would use the
following template: 000\-0000;0 (the dash is a literal
value and appears automatically as the user
enters the telephone number).
The semicolon and zero at the end of this input mask
are important because, as the on-line help system
points out, an input mask value actually consists of
three parts (or “arguments”), each separated by a
semicolon:
• the actual template (e.g., 000\-0000),
• a value (0 or 1) that tells Access how to deal with
literal characters, and
• the character to use as a place holder (showing
the user how many characters to enter).
When you use a literal character in an input mask,
the second argument determines whether the literal
value is simply displayed or displayed and stored in
the table as part of the data.
For example, if you use the input mask 000\-
0000;1, Access will not store the dash with the telephone
number. Thus, although the input mask will
always display the number as “822-6109”, the number
is actually stored as “8226109”. By using the
Application to the assignment 2. Tables
Next Home Previous 17 o f 18
input mask 000\-0000;0, however, you are telling
Access to store the dash with the rest of the data.
If you use the wizard to create an input mask,
it asks you a simple question about storing literal
values (as shown in Figure 2.8) and fills
in the second argument accordingly. However,
if you create the input mask manually,
you should be aware that by default, Access
does not store literal values. In other words,
the input mask 000\-0000 is identical to the
input mask 000\-0000;1. This has important
consequences if the field in question is
subject to referential integrity constraints (the
value “822-6109” is not the same as
“8226109”).
2.5 Application to the assignment
You now have the skills necessary to implement your
tables.
• Create all the tables required for the assignment.
• Use the autonumber data type (counter in version
2.0) for your primary keys where appropriate.
• Specify field properties such as captions, input
mask, and defaults where appropriate.
If you create an input mask for ProductID,
ensure you understand the implications of
Section 2.4.2.5.
• Set the Default property of the OrderDate field
so that the current date is automatically inserted
into the field when a new order is created (hint:
see the Date() function in the on-line help system).
Application to the assignment 2. Tables
Next Home Previous 18 o f 18
• Do not forget to modify your Products table (the
data types, lengths, and field properties of
imported tables normally need to be fine tuned)
• Populate (enter data into) your master tables. Do
not populate your transaction tables.
For the purpose of the assignment, the term
“transaction” tables refers to tables that contain
information about individual transactions
(e.g., Orders, OrderDetails, Shipments,
ShipmentDetails). “Master”
tables, in contrast, are tables that either do
not contain information about transactions
(e.g., Customers) or contain only summary
or status information about transactions (e.g.,
BackOrders).
Monday, February 9, 2009
Sunday, February 8, 2009
Learn MsAccess
© Michael Brydon (brydon@unixg.ubc.ca)
Last update: 24-Aug-1997 Next Home Previous 1 o f 17
Access Tutorial 1: Introduction to Microsoft Access
The purpose of these tutorials is not to teach you
Microsoft Access, but rather to teach you some
generic information systems concepts and skills
using Access. Of course, as a side effect, you will
learn a great deal about the software—enough to
write your own useful applications. However, keep in
mind that Access is an enormously complex, nearlyindustrial-
strength software development environment.
The material here only scrapes the surface of
Access development and database programming.
1.1 Introduction: What is Access?
Microsoft Access is a relational database management
system (DBMS). At the most basic level, a
DBMS is a program that facilitates the storage and
retrieval of structured information on a computer’s
hard drive. Examples of well-know industrial-strength
relational DBMSes include
• Oracle
• Microsoft SQL Server
• IBM DB2
• Informix
Well-know PC-based (“desktop”) relational DBMSes
include
• Microsoft Access
• Microsoft FoxPro
• Borland dBase
1.1.1 The many faces of Access
Microsoft generally likes to incorporate as many features
as possible into its products. For example, the
Access package contains the following elements:
• a relational database system that supports two
industry standard query languages: Structured
Query Language (SQL) and Query By Example
(QBE);
Introduction: What is Access? 1. Introduction to Microsoft Access
Next Home Previous 2 o f 17
• a full-featured procedural programming language—
essentially a subset of Visual Basic,
• a simplified procedural macro language unique
to Access;
• a rapid application development environment
complete with visual form and report development
tools;
• a sprinkling of objected-oriented extensions;
and,
• various wizards and builders to make development
easier.
For new users, these “multiple personalities” can be
a source of enormous frustration. The problem is
that each personality is based on a different set of
assumptions and a different view of computing. For
instance,
• the relational database personality expects you
to view your application as sets of data;
• the procedural programming personality expects
you to view your application as commands to be
executed sequentially;
• the object-oriented personality expects you to
view your application as objects which encapsulate
state and behavior information.
Microsoft makes no effort to provide an overall logical
integration of these personalities (indeed, it is
unlikely that such an integration is possible). Instead,
it is up to you as a developer to pick and choose the
best approach to implementing your application.
Since there are often several vastly different ways to
implement a particular feature in Access, recognizing
the different personalities and exploiting the best
features (and avoiding the pitfalls) of each are important
skills for Access developers.
The advantage of these multiple personalities is that
it is possible to use Access to learn about an enormous
range of information systems concepts without
Learning objectives 1. Introduction to Microsoft Access
Next Home Previous 3 o f 17
having to interact with a large number of “single-personality”
tools, for example:
• Oracle for relational databases
• PowerBuilder for rapid applications development,
• SmallTalk for object-oriented programming.
Keep this advantage in mind as we switch back and
forth between personalities and different computing
paradigms.
1.1.2 What is in an Access database
file?
Although the term “database” typically refers to a collection
of related data tables, an Access database
includes more than just data. In addition to tables, an
Access database file contains several different types
of database objects:
• saved queries for organizing data,
• forms for interacting with the data on screen,
• reports for printing results,
• macros and Visual Basic programs for extending
the functionality of database applications.
All these database objects are stored in a single file
named.mdb. When you are running
Access, a temporary “locking” file named.
ldb is also created. You can safely ignore
the *.ldb file; everything of value is in the *.mdb file.
1.2 Learning objectives
How do I get started?
How do I determine the version I am using?
How do I create or edit a database object?
What is the database window and what does
it contain?
How do I import an Excel spreadsheet?
How do I delete or rename database objects?
Tutorial exercises 1. Introduction to Microsoft Access
Next Home Previous 4 o f 17
How do I get help from the on-line help
system?
How do I compact a database to save space?
1.3 Tutorial exercises
In this tutorial, you will start by creating a new database
file.
1.3.1 Starting Access
• To start Access, you double click the Access icon
( for version 8.0 and 7.0 or for version
2.0) from within Microsoft Windows.
If you are working in the Commerce PC Lab, you will
be working with Access version 2.0. If you are working
at home, you will able be to tell what version you
are using by watching the screen “splash” as the program
loads. Alternatively, select Help > About
Access from the main menu to see which version
you are using.
All the screen shots in these tutorials are
taken from Access version 7.0 (released as
part of Office 95). Although there are some
important differences between version 2.0
and version 7.0, the concepts covered here
are the same for both. Version 8.0 (released
as part of Office 97) is only slightly different
from version 7.0.
Whenever the instructions given in the tutorial
differ significantly from version 7.0, a warning
box such as this is used.
1.3.2 Creating a new database
• Follow the directions in Figure 1.1 to create a
new database file called myfile.mdb.
Tutorial exercises 1. Introduction to Microsoft Access
Next Home Previous 5 o f 17
FIGURE 1.1: Select the name and location of your new (empty) database.
Create a new database by selecting File >
New from the main menu or by clicking the
“new database” button on the tool bar.
Type in a new database name and press Enter.
Note that you are limited to 8-letter names in
version 2.0.
Tutorial exercises 1. Introduction to Microsoft Access
Next Home Previous 6 o f 17
• Examine the main features of the database window—
including the tabs for viewing the different
database objects—as shown in Figure 1.2.
1.3.3 Opening an existing database
Since an empty database file is not particularly interesting,
you are provided with an existing database
file containing information about university courses.
For the remainder of this tutorial, we will use a file
called univ0_v7.mdb, which is available from the
tutorial’s Internet site.
If you are using version 2.0, you will need to
use the univ0_v2.mdb database instead.
Although you can open a version 2.0 database
with version 7.0, you cannot open a version
7.0 database with version 2.0. Importing
and exporting across versions is possible,
however.
If you are using version 8.0, you can use
either univ0_v2.mdb or univ0_v7.mdb for
the tutorials. When you open the file, Access
will ask you if you want to convert it to version
8.0. Select yes and provide a new name for
the converted file (e.g., univ0_v8.mdb)
• Open the univ0_v x.mdb file and examine the
contents of the Sections table, as shown in
Figure 1.3.
1.3.4 Importing data from other
applications
Access makes it easy to import data from other
applications. In this section, you will create a new
table using data from an Excel spreadsheet.
• Select File > Get External Data > Import from the
main menu and import the depts.xls spread-
Tutorial exercises 1. Introduction to Microsoft Access
Next Home Previous 7 o f 17
FIGURE 1.2: The database window contains all the database objects for a particular application.
The database window is always
available from the Window menu.
Tables —
contain data
in rows and
columns.
Queries — allow the
information in
tables to be sorted,
filtered, and shown
in different ways. Forms — are for
displaying
information on
the screen.
Reports —are
for organizing
and printing
information.
Macros — are sets of highlevel
commands that can be
used to process data and
perform repetitive tasks.
Modules —
contain Visual
Basic
procedures and
functions.
Tutorial exercises 1. Introduction to Microsoft Access
Next Home Previous 8 o f 17
FIGURE 1.3: Open the univ0_vx.mdb file for the version of Access that you are using and then
open the Sections table
Select File > Open Database
from the main menu.
Select the
correct file and
open the
Sections
table.
You can open a
database object for
viewing, for
modification, or
create a new object.
Tutorial exercises 1. Introduction to Microsoft Access
Next Home Previous 9 o f 17
sheet as a new table called Departments (see
Figure 1.4).
In version 2.0, the menu structure is slightly
different. As such, you must use File > Import.
• Use the import wizard specify the basic import
parameters. You should accept all the defaults
provided by the wizard except for those shown in
Figure 1.5.
• Double click the Departments table to ensure it
was imported correctly.
If you make a mistake, you can rename or
delete a table (or any database object in the
database window) by selecting it and rightclicking
(pressing the right mouse button
once).
1.3.5 Getting help
A recent trend in commercial software (especially
from Microsoft) is a reliance on on-line help and documentation
in lieu of printed manuals. As a consequence,
a good understanding of how to use the online
help system is essential for learning any new
software. In this section, you will use Access’ on-line
help system to tell you how to compact a database.
• Press F1 to invoke the on-line help system. Find
information on compacting a database, as shown
in Figure 1.6.
• Familiarize yourself with the basic elements of
the help window as shown in Figure 1.7.
1.3.6 Compacting your database
• Follow the directions provided by the on-line help
window shown in Figure 1.7 to compact your
database.
Tutorial exercises 1. Introduction to Microsoft Access
Next Home Previous 10 o f 17
Select File > Get External Data >
Import from the from the main menu
and move the directory containing the
file you want to import.
Select files of type *.xls (files
with that extension will show in
the file window).
Double-click depts.xls.
FIGURE 1.4: Import the dept.xls spreadsheet as a table called Departments.
Tutorial exercises 1. Introduction to Microsoft Access
Next Home Previous 11 o f 17
FIGURE 1.5: Use the spreadsheet import wizard to import the Excel file.
Select the first row contains
column headings option so
that the column headings in the
spreadsheet are not interpreted
as data.
Since we have not talked
about primary keys yet,
select no primary key.
Tutorial exercises 1. Introduction to Microsoft Access
Next Home Previous 12 o f 17
FIGURE 1.6: Use the help system to find
information on a specific topic
Type in the first few
letters of the topic you
are looking for.
Select the best match from
the list (i.e., “compacting
databases”) and doubleclick
to get a list of topics.
Double click the most
promising entry in this list
to get the actual help topic.
For most students, the help
system in Access version
2.0 is easier to navigate.
Use the “cue cards” in
version 2.0 to get step-bystep
instructions for many
operations.
The Index is the best place to
start when you are looking for a
specific topic. If you need more
structured information or are
looking for an overview, use the
Contents tab.
Tutorial exercises 1. Introduction to Microsoft Access
Next Home Previous 13 o f 17
FIGURE 1.7: Follow the instructions provided by help to compact your database
Press help topics to return to the
index.
Minimize (rather than close) help
when you are working so that you can
use the Back button to return to
previously visited topics without
repeating the search.
Words underlined with a dashed line
provide important definitions.
Discussion 1. Introduction to Microsoft Access
Next Home Previous 14 o f 17
1.4 Discussion
1.4.1 The database file in Access
The term “database” means different things depending
on the DBMS used. For example in dBase IV, a
database is a file (.dbf) containing a
single table. Forms and reports are also stored as
individual files with different extensions. The net
result is a clutter of files.
In contrast, an Oracle database has virtually no relationship
to individual files or individual projects. For
instance, a database may contain many tables from
different projects/applications and may also be
stored split into one or more files (perhaps on different
machines).
Access strikes a convenient balance—all the
“objects” (tables, queries, forms, reports, etc.) for a
single project/application are stored in a single file.
1.4.2 Compacting a database
As the help system points out, Access database files
can become highly fragmented and grow to become
much larger than you might expect given the amount
of data they contain (e.g., multiple megabytes for a
handful of records). Compacting the database from
time to time eliminates fragmentation and can dramatically
reduce the disk space requirement of your
database.
1.4.3 Renaming a database
It is often the case that you are working with a database
and want to save it under a different name or
save it on to a different disk drive. However, one
command on the File menu that is conspicuous by its
absence is Save As.
However, when compacting your database, Access
asks for the name and destination of the compacted
file. As a result, the compact database utility can be
Discussion 1. Introduction to Microsoft Access
Next Home Previous 15 o f 17
used as a substitute for the Save As command. This
is especially useful in situations in which you cannot
use the operating system to rename a file (e.g.,
when you do not have access to the Windows file
manager).
1.4.4 Developing applications in Access
In general, there are two basic approaches to developing
information systems:
• in-depth systems analysis, design, and implementation,
• rapid prototyping (in which analysis, design, and
implementation are done iteratively)
Access provides a number of features (such as
graphical design tools, wizards, and a high-level
macro language) that facilitate rapid prototyping.
Since you are going to build a small system and
since time is limited, you will use a rapid prototyping
approach to build your application. The recommended
sequence for prototyping using Access is
the following:
1. Model the information of interest in terms of entities
and relationships between the entities (this is
covered in the lecture portion of the course).
2. Create a table for each entity (Tutorial 2).
3. Specify the relationships between the tables
(Tutorial 3).
4. Organize the information in your tables using
queries (Tutorial 4, Tutorial 5, Tutorial 10)
5. Create forms and reports to support input and
output transactions (Tutorial 6, Tutorial 7).
6. Enhance you forms with input controls
(Tutorial 8)
7. Create action queries (Tutorial 11), macros
(Tutorial 13), or Visual Basic programs
(Tutorial 12, Tutorial 14) to perform the transaction
processing functions of the application.
Application to the assignment 1. Introduction to Microsoft Access
Next Home Previous 16 o f 17
8. Create “triggers” (procedures attached to events)
to automate certain repetitive tasks (Tutorial 15).
1.4.5 Use of linked tables
Most professional Access developers do not put their
tables in the same database file as their queries,
forms, reports, and so on. The reason for this is simple:
keep the application’s data and interface separate.
Access allows you to use the “linked table” feature to
link two database files: one containing all the tables
(“data”) and another containing all the interface and
logic elements of the application (“interface”). The
linked tables from the data file show up in the interface
file with little arrows (indicating that they are not
actually stored in the interface file).
In this way, you can modify or update the interface
file without affecting the actual data in any way. You
just copy the new interface file over to the user’s
machine, update the links to the data file, and the
upgrade is done.
Do not used linked tables in the assignment.
The links are dependent on the absolute
directory structure. As a result, if the directory
structure on your machine is different from
that on the marker’s machine, the marker will
not be able to use your application without
first updating the links (a time consuming process
for a large number of assignments).
1.5 Application to the assignment
After completing this tutorial you should be ready to
create the database file that you will use for the
remainder of the course.
1. Create an empty database file called groupID>.mdb. Remember that your group
number consists of eight digits.
Application to the assignment 1. Introduction to Microsoft Access
Next Home Previous 17 o f 17
2. Import the inventor.xls spreadsheet as your
Products table.
3. Use the compact utility to make a backup copy of
your database (use a different name such as
backup.mdb).
Last update: 24-Aug-1997 Next Home Previous 1 o f 17
Access Tutorial 1: Introduction to Microsoft Access
The purpose of these tutorials is not to teach you
Microsoft Access, but rather to teach you some
generic information systems concepts and skills
using Access. Of course, as a side effect, you will
learn a great deal about the software—enough to
write your own useful applications. However, keep in
mind that Access is an enormously complex, nearlyindustrial-
strength software development environment.
The material here only scrapes the surface of
Access development and database programming.
1.1 Introduction: What is Access?
Microsoft Access is a relational database management
system (DBMS). At the most basic level, a
DBMS is a program that facilitates the storage and
retrieval of structured information on a computer’s
hard drive. Examples of well-know industrial-strength
relational DBMSes include
• Oracle
• Microsoft SQL Server
• IBM DB2
• Informix
Well-know PC-based (“desktop”) relational DBMSes
include
• Microsoft Access
• Microsoft FoxPro
• Borland dBase
1.1.1 The many faces of Access
Microsoft generally likes to incorporate as many features
as possible into its products. For example, the
Access package contains the following elements:
• a relational database system that supports two
industry standard query languages: Structured
Query Language (SQL) and Query By Example
(QBE);
Introduction: What is Access? 1. Introduction to Microsoft Access
Next Home Previous 2 o f 17
• a full-featured procedural programming language—
essentially a subset of Visual Basic,
• a simplified procedural macro language unique
to Access;
• a rapid application development environment
complete with visual form and report development
tools;
• a sprinkling of objected-oriented extensions;
and,
• various wizards and builders to make development
easier.
For new users, these “multiple personalities” can be
a source of enormous frustration. The problem is
that each personality is based on a different set of
assumptions and a different view of computing. For
instance,
• the relational database personality expects you
to view your application as sets of data;
• the procedural programming personality expects
you to view your application as commands to be
executed sequentially;
• the object-oriented personality expects you to
view your application as objects which encapsulate
state and behavior information.
Microsoft makes no effort to provide an overall logical
integration of these personalities (indeed, it is
unlikely that such an integration is possible). Instead,
it is up to you as a developer to pick and choose the
best approach to implementing your application.
Since there are often several vastly different ways to
implement a particular feature in Access, recognizing
the different personalities and exploiting the best
features (and avoiding the pitfalls) of each are important
skills for Access developers.
The advantage of these multiple personalities is that
it is possible to use Access to learn about an enormous
range of information systems concepts without
Learning objectives 1. Introduction to Microsoft Access
Next Home Previous 3 o f 17
having to interact with a large number of “single-personality”
tools, for example:
• Oracle for relational databases
• PowerBuilder for rapid applications development,
• SmallTalk for object-oriented programming.
Keep this advantage in mind as we switch back and
forth between personalities and different computing
paradigms.
1.1.2 What is in an Access database
file?
Although the term “database” typically refers to a collection
of related data tables, an Access database
includes more than just data. In addition to tables, an
Access database file contains several different types
of database objects:
• saved queries for organizing data,
• forms for interacting with the data on screen,
• reports for printing results,
• macros and Visual Basic programs for extending
the functionality of database applications.
All these database objects are stored in a single file
named
Access, a temporary “locking” file named
ldb is also created. You can safely ignore
the *.ldb file; everything of value is in the *.mdb file.
1.2 Learning objectives
How do I get started?
How do I determine the version I am using?
How do I create or edit a database object?
What is the database window and what does
it contain?
How do I import an Excel spreadsheet?
How do I delete or rename database objects?
Tutorial exercises 1. Introduction to Microsoft Access
Next Home Previous 4 o f 17
How do I get help from the on-line help
system?
How do I compact a database to save space?
1.3 Tutorial exercises
In this tutorial, you will start by creating a new database
file.
1.3.1 Starting Access
• To start Access, you double click the Access icon
( for version 8.0 and 7.0 or for version
2.0) from within Microsoft Windows.
If you are working in the Commerce PC Lab, you will
be working with Access version 2.0. If you are working
at home, you will able be to tell what version you
are using by watching the screen “splash” as the program
loads. Alternatively, select Help > About
Access from the main menu to see which version
you are using.
All the screen shots in these tutorials are
taken from Access version 7.0 (released as
part of Office 95). Although there are some
important differences between version 2.0
and version 7.0, the concepts covered here
are the same for both. Version 8.0 (released
as part of Office 97) is only slightly different
from version 7.0.
Whenever the instructions given in the tutorial
differ significantly from version 7.0, a warning
box such as this is used.
1.3.2 Creating a new database
• Follow the directions in Figure 1.1 to create a
new database file called myfile.mdb.
Tutorial exercises 1. Introduction to Microsoft Access
Next Home Previous 5 o f 17
FIGURE 1.1: Select the name and location of your new (empty) database.
Create a new database by selecting File >
New from the main menu or by clicking the
“new database” button on the tool bar.
Type in a new database name and press Enter.
Note that you are limited to 8-letter names in
version 2.0.
Tutorial exercises 1. Introduction to Microsoft Access
Next Home Previous 6 o f 17
• Examine the main features of the database window—
including the tabs for viewing the different
database objects—as shown in Figure 1.2.
1.3.3 Opening an existing database
Since an empty database file is not particularly interesting,
you are provided with an existing database
file containing information about university courses.
For the remainder of this tutorial, we will use a file
called univ0_v7.mdb, which is available from the
tutorial’s Internet site.
If you are using version 2.0, you will need to
use the univ0_v2.mdb database instead.
Although you can open a version 2.0 database
with version 7.0, you cannot open a version
7.0 database with version 2.0. Importing
and exporting across versions is possible,
however.
If you are using version 8.0, you can use
either univ0_v2.mdb or univ0_v7.mdb for
the tutorials. When you open the file, Access
will ask you if you want to convert it to version
8.0. Select yes and provide a new name for
the converted file (e.g., univ0_v8.mdb)
• Open the univ0_v x.mdb file and examine the
contents of the Sections table, as shown in
Figure 1.3.
1.3.4 Importing data from other
applications
Access makes it easy to import data from other
applications. In this section, you will create a new
table using data from an Excel spreadsheet.
• Select File > Get External Data > Import from the
main menu and import the depts.xls spread-
Tutorial exercises 1. Introduction to Microsoft Access
Next Home Previous 7 o f 17
FIGURE 1.2: The database window contains all the database objects for a particular application.
The database window is always
available from the Window menu.
Tables —
contain data
in rows and
columns.
Queries — allow the
information in
tables to be sorted,
filtered, and shown
in different ways. Forms — are for
displaying
information on
the screen.
Reports —are
for organizing
and printing
information.
Macros — are sets of highlevel
commands that can be
used to process data and
perform repetitive tasks.
Modules —
contain Visual
Basic
procedures and
functions.
Tutorial exercises 1. Introduction to Microsoft Access
Next Home Previous 8 o f 17
FIGURE 1.3: Open the univ0_vx.mdb file for the version of Access that you are using and then
open the Sections table
Select File > Open Database
from the main menu.
Select the
correct file and
open the
Sections
table.
You can open a
database object for
viewing, for
modification, or
create a new object.
Tutorial exercises 1. Introduction to Microsoft Access
Next Home Previous 9 o f 17
sheet as a new table called Departments (see
Figure 1.4).
In version 2.0, the menu structure is slightly
different. As such, you must use File > Import.
• Use the import wizard specify the basic import
parameters. You should accept all the defaults
provided by the wizard except for those shown in
Figure 1.5.
• Double click the Departments table to ensure it
was imported correctly.
If you make a mistake, you can rename or
delete a table (or any database object in the
database window) by selecting it and rightclicking
(pressing the right mouse button
once).
1.3.5 Getting help
A recent trend in commercial software (especially
from Microsoft) is a reliance on on-line help and documentation
in lieu of printed manuals. As a consequence,
a good understanding of how to use the online
help system is essential for learning any new
software. In this section, you will use Access’ on-line
help system to tell you how to compact a database.
• Press F1 to invoke the on-line help system. Find
information on compacting a database, as shown
in Figure 1.6.
• Familiarize yourself with the basic elements of
the help window as shown in Figure 1.7.
1.3.6 Compacting your database
• Follow the directions provided by the on-line help
window shown in Figure 1.7 to compact your
database.
Tutorial exercises 1. Introduction to Microsoft Access
Next Home Previous 10 o f 17
Select File > Get External Data >
Import from the from the main menu
and move the directory containing the
file you want to import.
Select files of type *.xls (files
with that extension will show in
the file window).
Double-click depts.xls.
FIGURE 1.4: Import the dept.xls spreadsheet as a table called Departments.
Tutorial exercises 1. Introduction to Microsoft Access
Next Home Previous 11 o f 17
FIGURE 1.5: Use the spreadsheet import wizard to import the Excel file.
Select the first row contains
column headings option so
that the column headings in the
spreadsheet are not interpreted
as data.
Since we have not talked
about primary keys yet,
select no primary key.
Tutorial exercises 1. Introduction to Microsoft Access
Next Home Previous 12 o f 17
FIGURE 1.6: Use the help system to find
information on a specific topic
Type in the first few
letters of the topic you
are looking for.
Select the best match from
the list (i.e., “compacting
databases”) and doubleclick
to get a list of topics.
Double click the most
promising entry in this list
to get the actual help topic.
For most students, the help
system in Access version
2.0 is easier to navigate.
Use the “cue cards” in
version 2.0 to get step-bystep
instructions for many
operations.
The Index is the best place to
start when you are looking for a
specific topic. If you need more
structured information or are
looking for an overview, use the
Contents tab.
Tutorial exercises 1. Introduction to Microsoft Access
Next Home Previous 13 o f 17
FIGURE 1.7: Follow the instructions provided by help to compact your database
Press help topics to return to the
index.
Minimize (rather than close) help
when you are working so that you can
use the Back button to return to
previously visited topics without
repeating the search.
Words underlined with a dashed line
provide important definitions.
Discussion 1. Introduction to Microsoft Access
Next Home Previous 14 o f 17
1.4 Discussion
1.4.1 The database file in Access
The term “database” means different things depending
on the DBMS used. For example in dBase IV, a
database is a file (
single table. Forms and reports are also stored as
individual files with different extensions. The net
result is a clutter of files.
In contrast, an Oracle database has virtually no relationship
to individual files or individual projects. For
instance, a database may contain many tables from
different projects/applications and may also be
stored split into one or more files (perhaps on different
machines).
Access strikes a convenient balance—all the
“objects” (tables, queries, forms, reports, etc.) for a
single project/application are stored in a single file.
1.4.2 Compacting a database
As the help system points out, Access database files
can become highly fragmented and grow to become
much larger than you might expect given the amount
of data they contain (e.g., multiple megabytes for a
handful of records). Compacting the database from
time to time eliminates fragmentation and can dramatically
reduce the disk space requirement of your
database.
1.4.3 Renaming a database
It is often the case that you are working with a database
and want to save it under a different name or
save it on to a different disk drive. However, one
command on the File menu that is conspicuous by its
absence is Save As.
However, when compacting your database, Access
asks for the name and destination of the compacted
file. As a result, the compact database utility can be
Discussion 1. Introduction to Microsoft Access
Next Home Previous 15 o f 17
used as a substitute for the Save As command. This
is especially useful in situations in which you cannot
use the operating system to rename a file (e.g.,
when you do not have access to the Windows file
manager).
1.4.4 Developing applications in Access
In general, there are two basic approaches to developing
information systems:
• in-depth systems analysis, design, and implementation,
• rapid prototyping (in which analysis, design, and
implementation are done iteratively)
Access provides a number of features (such as
graphical design tools, wizards, and a high-level
macro language) that facilitate rapid prototyping.
Since you are going to build a small system and
since time is limited, you will use a rapid prototyping
approach to build your application. The recommended
sequence for prototyping using Access is
the following:
1. Model the information of interest in terms of entities
and relationships between the entities (this is
covered in the lecture portion of the course).
2. Create a table for each entity (Tutorial 2).
3. Specify the relationships between the tables
(Tutorial 3).
4. Organize the information in your tables using
queries (Tutorial 4, Tutorial 5, Tutorial 10)
5. Create forms and reports to support input and
output transactions (Tutorial 6, Tutorial 7).
6. Enhance you forms with input controls
(Tutorial 8)
7. Create action queries (Tutorial 11), macros
(Tutorial 13), or Visual Basic programs
(Tutorial 12, Tutorial 14) to perform the transaction
processing functions of the application.
Application to the assignment 1. Introduction to Microsoft Access
Next Home Previous 16 o f 17
8. Create “triggers” (procedures attached to events)
to automate certain repetitive tasks (Tutorial 15).
1.4.5 Use of linked tables
Most professional Access developers do not put their
tables in the same database file as their queries,
forms, reports, and so on. The reason for this is simple:
keep the application’s data and interface separate.
Access allows you to use the “linked table” feature to
link two database files: one containing all the tables
(“data”) and another containing all the interface and
logic elements of the application (“interface”). The
linked tables from the data file show up in the interface
file with little arrows (indicating that they are not
actually stored in the interface file).
In this way, you can modify or update the interface
file without affecting the actual data in any way. You
just copy the new interface file over to the user’s
machine, update the links to the data file, and the
upgrade is done.
Do not used linked tables in the assignment.
The links are dependent on the absolute
directory structure. As a result, if the directory
structure on your machine is different from
that on the marker’s machine, the marker will
not be able to use your application without
first updating the links (a time consuming process
for a large number of assignments).
1.5 Application to the assignment
After completing this tutorial you should be ready to
create the database file that you will use for the
remainder of the course.
1. Create an empty database file called
number consists of eight digits.
Application to the assignment 1. Introduction to Microsoft Access
Next Home Previous 17 o f 17
2. Import the inventor.xls spreadsheet as your
Products table.
3. Use the compact utility to make a backup copy of
your database (use a different name such as
backup.mdb).
Subscribe to:
Posts (Atom)