Access 2007 Tutorial
Access 2007 Tutorial
Access 2007
Tutorial
Contents Page
Introduction ........................................................................................................................... 1
Lets Get Started ................................................................................................................... 2
Creating Tables..................................................................................................................... 3
Creating Relationships and Enforcing Referential Integrity .................................................... 8
Adding Data ........................................................................................................................ 12
Creating Queries ................................................................................................................. 16
Reports ............................................................................................................................... 25
Forms ................................................................................................................................. 35
Creating a Switchboard ....................................................................................................... 39
General Design Considerations .......................................................................................... 43
Useful Resources................................................................................................................ 43
Introduction
This tutorial is an introduction to using Microsoft Access 2007. In this tutorial a database
with 4 tables will be created, data added to these tables, queries created to obtain
information from the database, and reports to display information from the database.
The database being constructed is for a basic sales system and contains the following tables
and attributes with the stated data types and sizes:
Table
Customer
Inventory
Employee
Sale
Attribute
CustomerID
CustomerFirstName
CustomerLastName
CustomerAddress
CustomerSuburb
CustomerCity
CustomerPostCode
CustomerPhoneNumber
Data Type
AutoNumber
Text
Text
Text
Text
Text
Text
Text
Size
50
50
50
50
50
4
15
Required
Y
Y
Y
Y
N
Y
N
N
InventoryID
InventoryName
InventoryDescription
AutoNumber
Text
Text
50
255
Y
Y
N
EmployeeID
EmployeeFirstName
EmployeeLastName
EmployeeExtension
AutoNumber
Text
Text
Text
50
50
4
Y
Y
Y
N
SaleID
CustomerID
InventoryID
EmployeeID
SaleDate
SaleQuantity
UnitSalePrice
AutoNumber
Number
Number
Number
DateTime
Number
Currency
Y
LongInteger Y
LongInteger Y
LongInteger Y
Y
Integer
Y
Y
Notice that the names of each attribute are typed with no spaces between the words, but
each new word starts with a capital. This is called CamelCase. Dont use spaces in field
names because different database programmes treat these differently and it can also cause
problems with creating queries later.
Also notice that each attribute name has the table name in front of it. This is not always
done, but is useful when the same field name may be used for different tables. For example,
this database also has an Employee table where the employee name is included. By
including the table name in front of the field name, it is easier to determine which field is
being referred to when using queries and reports.
Give the database a suitable name BasicSalesSystem and choose a folder to save it to by
clicking the folder icon.
Click Create
Creating Tables
Steps for creating a Table
1. Click Create Table Design
2. Enter Field names, data types, and descriptions (optional)
3. Enter properties for fields
4. Set the primary key(s)
5. Save the table design (and name the table)
Creating the Customer Table
Select the Create Tab and Click the Table Design button
The CustomerID is going to be the Primary Key, so with the CustomerID field selected, click
the Primary Key button on the ribbon. Notice the key which now appears next to
CustomerID
Move down to the next row, and type CustomerFirstName in the field name cell, choose Text
as the data type, add a suitable description.
In the Field Properties Box, change the Field Size to 50, and Required to Yes
Now add the rest of the Attributes with the following properties
Table
Customer
Attribute
CustomerID
CustomerFirstName
CustomerLastName
CustomerAddress
CustomerSuburb
CustomerCity
CustomerPostCode
CustomerPhoneNumber
Data Type
AutoNumber
Text
Text
Text
Text
Text
Text
Text
Size
50
50
50
50
50
4
15
Required
Y
Y
Y
Y
N
Y
N
N
Table
Customer
Inventory
Employee
Primary Key
Attribute
CustomerID
InventoryID
EmployeeID
Table
Sale
Sale
Sale
Foreign Key
Attribute
CustomerID
InventoryID
EmployeeID
The Primary/Foreign key link allows any of the information in the primary keys table to be
accessed via the link. For example, because the Sale table has the CustomerID in it, a
query run across the Sale and Customer tables will allow the customer name to be displayed
with the details of the sale. More about this later.
One of the advantages of the relational database design is to ensure that only valid data can
be entered for the foreign key data items. This is done by enforcing referential integrity
which means that before a value can be entered into the foreign key attribute, it must already
exist in the table containing the primary key. This means when entering data, care has to be
taken about the order the data is entered: First enter data in the primary key table and then
enter the data in the foreign key table. For this tutorial database, data will need to be added
to the Customer, Inventory and Employee tables before anything can be added to the Sale
table.
Click on Database Tools Relationships
To create the relationship, click and drag the primary key attribute to the appropriate attribute
in the related table:
Click and Drag CustomerID from the Customer table to the CustomerID in the Sale table
10
11
Adding Data
Data can be added using the Datasheet View mode or by using a form (covered later).
Open the Customer table in View mode (Datasheet View)
Click on CustomerFirstName and type Bill, tab to CustomerLastName and type Smith etc.
The CustomerID does not need to be typed because it is an AutoNumber and is
automatically included by Access.
Type in the rest of the customer records.
Do the same thing for the other tables.
12
Table
Customer
Attribute
CustomerID
CustomerFirstName
CustomerLastName
CustomerAddress
1
2
3
4
5
Bill
Bob
Jane
Sue
Fred
Smith
Brown
Green
Cross
Brown
CustomerSuburb
InventoryID
InventoryName
InventoryDescription
1
2
3
4
5
Hammer
Screwdriver
Saw
Spanner
Pliers
CustomerCity
CustomerPostCode
CustomerPhoneNumber
Nelson
Wellington
Auckland
Nelson
Picton
7055
6986
1436
7073
7125
03123456
0274567898
04573953
03850345
0277684930
Inventory
Phillips
Employee
EmployeeID
EmployeeFirstName
EmployeeLastName
EmployeeExtension
1
2
3
4
5
Joy
Jack
Gary
Gail
Lee
Smith
Trigger
Wood
Smith
Drake
123
124
125
126
Sale
SaleID
CustomerID
InventoryID
EmployeeID
SaleDate
SaleQuantity
UnitSalePrice
1
2
3
4
5
1
1
2
4
3
1
3
2
4
4
2
5
1
4
2
12/1/09
6/2/09
14/2/09
28/2/09
12/3/09
3
1
4
1
5
15.99
17.99
6.95
9.99
9.99
13
Customer Table
Inventory Table
Employee Table
Sale Table
14
15
Creating Queries
Now that the data has been added to the tables, it can be used to produce results related to
a set of conditions given to it. This is known as queries. Queries can be from one table or
from a number of tables.
Queries
Select Create Query Design
Steps
1.
2.
3.
4.
5.
6.
Important: When creating queries check that the results seem to be reasonable. When
there is only a small dataset, look at the data and determine what the results should be
before running the query and checking that the results obtained are the same.
16
17
Result
18
Select CustomerFirstName, CustomerLastName from the Customer table and the SaleDate
from the Sale table. Sort by the sale date.
Result
19
Adjust the query by showing only Bill Smiths sales by including Bill in Customer FirstName
and Smith in CustomerLastName.
Result
Change the query to show only those sales which occurred in February 2009
This can be done by typing >= 1/2/09 And <= 28/2/09 in the SaleDate criteria. When the
query is run, Access adds the # around each date.
Result
20
Result
21
Result
Result
22
Once the query has been run, the calculation will show [ ] around the table and attribute
names:
23
24
Reports
Reports are used to view information in the database. They can be created using a wizard
or manually and they can be modified to display the information in different ways. This
tutorial will only use the Report Wizard and making modifications to this. Reports can be
based on tables or on queries.
Select Create Report Wizard
Follow the instructions in the wizard to select the table or query and the desired fields. The
fields will be shown in the report in the order in which they are selected.
Report 1: Customer Phone List
Select
Select
Select
Select
25
Select a report layout (this example will use the tabular layout)
Select a report style (this example will use the office style)
Give the report a suitable name (eg Customer Phone List)
26
When the preview is closed, the report is shown in the Design View Mode where alterations
can be made to the formatting of the report.
Lets have a look at the formatting of the report.
The heading looks okay, but it would be better if it was centred.
The column headings are the table attributes and are in CamelCase. They also include the
word Customer in each one. A better format for the column headings would be to delete the
word Customer from each heading and to put a space between the words.
In Design View, the report is broken into a number of sections. The report header and page
header details are just headings and can easily be adjusted. The Detail section is linked to
the database table and fields. These can also be modified by changing their placement and
27
the size of the fields can be changed to display all of the data. The page footer shows the
date (=Now()) and the page number.
There are 2 ways to centre the report header. First the textbox containing the heading can
be moved and manually centred. Alternatively, the width of the textbox can be changed to
the width of the page and then the text can be centred.
Select the textbox
Click on the middle dot on the right of the textbox and drag it to the edge of the page
Click inside the textbox and then click the centre button.
Result
28
Click inside the textbox, delete the word Customer and put a space between Last and
Name
29
Finish selecting options presented by the wizard and preview the report
30
31
Extracts from the report after changing the report to landscape mode
32
Now, the report is not the nicest. Switch to the Design View mode and modify the report
format to look like the following:
33
It is possible to add new Page Headers and to modify the data displayed in the
InventoryName Footer and EmployeeFirstName Footer. The Property Sheet is useful to add
new headings so they have the same properties as the other headings.
Adjusted View
34
Forms
A form can be used to view, add, edit and delete data. Forms can be formatted in a way
which is useful for the user.
The easiest way to create a data entry form is to use the Form button
Select the table required
Click Create Form
Form 1: Creating a Customer Form
First select the Customer table
Then Click the Form button
35
Any related records in the Sale table are also shown, making it easy to add, edit or delete
these records.
Each Customer record can be displayed and new records added.
Form 2: Sale entry
At the moment, the fSale form could be used; however this is not very useful because the
only data captured are ID numbers.
To improve this form, the Sale table could be modified to include lookup lists for customer,
inventory, and employee to help the user to capture the correct information.
36
Steps
1.
2.
3.
4.
5.
The source is based on the Customer table, and the first 6 columns which is the
CustomerID, CustomerFirstName, CustomerLastName, CustomerAddress, CustomerSuburb
and CustomerCity. Basing this on the table is not the best design option because if the table
structure changes (eg columns are added, removed, or reordered), the look up table will be
inaccurate. Creating a customer query to include the required information is better. Try this
yourself.
To disable the SaleID in fSale2:
Click on SaleID textbox
Open the Property Sheet if it isnt already open
Select the Data tab
Change Enabled to No
37
NB If you use a form to update a table, the table needs to be closed for the update to be
shown.
38
Creating a Switchboard
Database Tools Switchboard Manager
39
Type Forms
Click OK
Create a page for Reports
With Sales System highlighted, click Edit
Click New
40
Click Ok
41
Then Click Close to exit from the Edit Switchboard Page to return to Switchboard Manager
With Forms selected, click Edit, then click New
Do the same for the rest of the items which need to be added to the switchboard.
Also add a Return option for each button with the command = go to switchboard, and Form
= The Main Switchboard name (Sales System).
Once the Switchboard is completed, close out of it.
There are now 2 new objects in the database Switchboard Items table and Switchboard
form.
42
Useful Resources
Microsoft Office Access 2007 Step by Step
Microsoft Office Access 2007 Bible
GCF Learn Free.org: Access 2007 Free Tutorial at
http://www.gcflearnfree.org/computer/topic.aspx?id=146
MS Access Tutorial at http://www.profsr.com/access/accless0.htm
43