ICDL for Educators Courseware – Database
Module 5
Read me first
The ICDL® Qualification
The International Computer Driving Licence® (or ICDL®) is the worldwide qualification which
enables people to demonstrate their competence in computer skills. The ICDL® consists of
seven module tests, which lead to the qualification.
The ECDL® Qualification
The European Computer Driving Licence® (or ECDL®) is the name by which the ICDL®
qualification is known in Europe.
ICDL for Educators Courseware
The ICDL for Educators courseware consists of the seven ICDL modules with a specific
focus on classroom use, plus additional Pupil Projects. The result is an ICDL experience that
is totally in context for schools.
The courseware addresses all the skills covered in the International Computer Driving
Licence® syllabus, therefore on completion of the courseware learners should feel confident
to undertake their ICDL® qualification.
ECDL for Educators Courseware is accredited by the ECDL Foundation Limited. The ECDL
Foundation is the global governing body for ECDL® and ICDL® accreditation.
European Computer Driving Licence, ECDL, International Computer Driving Licence, ICDL, e-Citizen and related logos are trade marks of The
European Computer Driving Licence Foundation Limited (“ECDL-F”) in Ireland and other countries.
Aston Swann and co is an entity independent of ECDL-F and is not associated with ECDL-F in any manner. This courseware publication may be
used to assist candidates to prepare for ECDL/ICDL tests. Neither ECDL-F nor Aston Swann and co warrants that the use of this courseware
publication will ensure passing of ECDL/ICDL tests. This courseware publication has been independently reviewed and approved by ECDL-F as
complying with the following standard:
Technical compliance with the learning objectives of ECDL/ICDL Syllabus Version 4.0.
Confirmation of this approval can be obtained by reviewing the Courseware Section of the website www.ecdl.com
The material contained in this courseware publication has not been reviewed for technical accuracy and does not guarantee that candidates will
pass ECDL/ICDL tests. Any and all assessment items and/or performance-based exercises contained in this courseware publication relate solely
to this publication and do not constitute or imply certification by ECDL-F in respect of ECDL/ICDL tests or any other ECDL-F test.
For details on sitting ECDL/ICDL tests and other ECDL-F tests in your country, please contact your country's National ECDL/ICDL designated
Licensee or visit ECDL-F’s web site at www.ecdl.com.
Candidates using this courseware publication must be registered with the National Licensee, before undertaking ECDL/ICDL tests. Without a
valid registration, ECDL/ICDL tests cannot be undertaken and no ECDL/ICDL certificate, nor any other form of recognition, can be given to a
candidate. Registration should be undertaken with your country's National ECDL/ICDL designated Licensee at any Approved ECDL/ICDL Test
Centre.
ECDL/ICDL Syllabus Version 4.0 is the official syllabus of the ECDL/ICDL certification programme at the date of approval of this courseware
publication
ECDL Version 4 Accredited Courseware
© Aston Swann 2006
i
ICDL for Educators Courseware – Database
Module 5
The Learning
ICDL for Educators Courseware can be delivered as a face-to-face (tutor led) programme,
as a self-study option, as workshops; or any combination of these options.
ICDL for Educators Courseware can be managed and supported on-line through Managed
Learning Environments, Virtual Learning Environments and Virtual School Environments.
The Content
Module 5: Database
The courseware for this module is contained within this workbook
The workbook consists of 3 Parts
Each Part takes approximately 3 hours to complete
Each Part is broken down into Examples
The Examples are based on classroom related documents.
Each Example is broken down into a series of Exercises
The Exercises cover the steps necessary to create the document in the current
Example
Each Exercise is written in a click-by-click format
The Exercises within the workbook cover the full range of the ICDL syllabus skill requirements
for this module. It is important that learners complete this module in full, in order to have
covered all of the syllabus requirements for Module 5.
It is also important to begin with Part 1, and work through to the end of Part 3, as the module
builds upon the skills learned in the earlier Exercises.
This ECDL Foundation approved courseware product incorporates
learning reinforcement exercises. These exercises are included to
help the candidate in their training for the ECDL/ICDL®.
The
exercises included in this courseware product are not ECDL/ICDL®
certification tests, and should not be construed in any way as
ECDL/ICDL® certification tests. For information about Authorised
ECDLICDL® Test Centres in different National Territories, please
refer to the ECDL Foundation website at www.ecdl.com.
ii
© Aston Swann 2006
ICDL for Educators Courseware – Database
Module 5
Opening and Saving Files
Some of the Exercises contained within this module require learners to open pre-prepared
files, and to save these files and others created during the training into the learner’s filing
system.
The pre-prepared files will initially be contained on a CD. It is the responsibility of the licence
holder to provide learners with a CD containing all the pre-prepared files.
If this is not
practical, it is the responsibility of the licence holder to provide learners with the pre-prepared
files electronically (locally, via Intranet or via a secure Internet web site). In this instance, the
licence holder should advise learners of the location of the files.
The Exercises give click-by-click instructions on how to open the pre-prepared file(s) from the
CD, and how to save files to the [My Documents] folder, or another, appropriate folder. If it is
not practical to save files to the [My Documents] folder, it is the responsibility of the licence
holder to advise learners of the drive, folders and sub-folder(s) in which the files should be
saved.
Instructions
Throughout the courseware, the following methods have been used:
•
Instructions are indicated by a bullet
The result of the instruction is a sub-bullet below
Exercise information is written without a bullet
Additional information is written in italics
We use the word “Click” for a button
We use the word “Select” for a menu
We use square brackets to indicate a [button name] and [menu name].
ICDL for Educators courseware is authored by Aston Swann and accredited by the ECDL Foundation Ltd.
ICDL for Educators courseware is a part of the ECDL for Educators courseware suite authored by Aston Swann.
All rights reserved.
V4.XP.03.06
Please contact us with any queries or feedback about this courseware:Aston Swann & Co.
Suite 1, 26-28 Aubrey Street, Hereford HR4 0BU, UK
T: +44 (0) 8454 304051
F: +44 (0) 8454 304052
E: ws@educatorsecdl.com
W: www.educatorsecdl.com
© Aston Swann 2006
iii
ICDL for Educators Courseware – Database
This page is left deliberately blank
iv
© Aston Swann 2006
Module 5
ICDL for Educators Courseware – Database
Module 5 Part 1
Databases
Part 1
Read me first ...............................................................................................................................i
Introduction to databases .......................................................................................................... 4
Useful Terms and Explanations ............................................................................................ 5
Example 1 – Using a database.................................................................................................. 8
Exercise 1
Exercise 2
Exercise 3
Exercise 4
Exercise 5
Exercise 6
Exercise 7
Exercise 8
Exercise 9
Exercise 10
Exercise 11
Exercise 12
Exercise 13
Exercise 14
Exercise 15
Exercise 16
Exercise 17
Exercise 18
Opening a database .................................................................................. 10
Understand the database design .............................................................. 15
Display the records in a form .................................................................... 16
Viewing records......................................................................................... 17
Using a form to add records...................................................................... 18
Save your work.......................................................................................... 19
Close and open forms ............................................................................... 20
Find information......................................................................................... 21
Look at different objects and views ........................................................... 24
View and navigate tables .......................................................................... 25
Navigate records ....................................................................................... 26
Amend records – add, edit, delete within a table ...................................... 27
Filter information........................................................................................ 29
Sort records............................................................................................... 31
Run a report .............................................................................................. 34
Run a query............................................................................................... 35
Relationships between tables ................................................................... 39
Close a database and Access................................................................... 40
Example 2 – Creating a database ........................................................................................... 41
Exercise 19
Exercise 20
Exercise 21
Exercise 22
Exercise 23
Exercise 24
Exercise 25
Exercise 26
Exercise 27
Exercise 28
Exercise 29
Exercise 30
Exercise 31
Exercise 32
Exercise 33
Exercise 34
Exercise 35
Design and plan a database ..................................................................... 41
Create a database..................................................................................... 45
Create tables ............................................................................................. 47
Change viewing mode............................................................................... 53
Modify field types....................................................................................... 54
Add a field ................................................................................................. 57
Add descriptions to help with data entry ................................................... 58
Create a table using design view .............................................................. 60
Create fields .............................................................................................. 61
Amend data types ..................................................................................... 62
Create a lookup column ............................................................................ 63
Create a primary key field ......................................................................... 65
Enter the records....................................................................................... 66
Create the session table ........................................................................... 67
Amend field format .................................................................................... 69
Link the tables ........................................................................................... 73
Create a query........................................................................................... 79
 Aston Swann 2006
1
ICDL for Educators Courseware – Database
Exercise 36
Exercise 37
Exercise 38
Exercise 39
Exercise 40
2
Module 5 Part 1
Create a form ............................................................................................ 83
Enter data using the new form .................................................................. 86
Previewing and printing ............................................................................. 89
Create a report .......................................................................................... 91
Closing Access.......................................................................................... 98
 Aston Swann 2006
ICDL for Educators Courseware – Database
Module 5 Part 1
Title bar
Menu bar
Main toolbar
Access main window
Object toolbar
Objects pane
Main database window
Status bar
 Aston Swann 2006
3
ICDL for Educators Courseware – Database
Module 5 Part 1
Introduction to databases
This three-hour session will cover the following:
Example 1: How to use a database that has already been created for you
Example 2: How to create a database
What is a database?
A database is an organised collection of information, stored in a structured
way. A telephone directory is a good example of a database, as the same
standard information is held on each person. Microsoft Access allows you to
create and use electronic databases to store and retrieve information.
Why use a database?
Storing information in a structured way allows it to be easily accessed and
organised either on the screen or in printed documentation. Using a database
allows information to be found quickly. This could be displayed on screen,
printed out, or substituted in documents for personalised letters and
certificates.
4
 Aston Swann 2006
ICDL for Educators Courseware – Database
Module 5 Part 1
Useful Terms and Explanations
Tables
Access holds its information in tables
Each table should be set up to hold one particular set of information. For
example, one table could contain details about pupils and another could
contain a list of after school clubs.
Two or more tables can be linked, so, for example, it would be easy to find
which pupil attended which club. Linking tables like this eliminates
duplication when entering information into the database.
Tables can also be called “Datasheets” in Access.
The information contained in tables can be presented in an attractive way
either on the screen (as a form) or on paper (as a report).
Tables contain records. Each record is one complete set of details. For
example, a record could contain all the information about one particular pupil,
or one after school club.
Each record is made up of fields. For example, a pupil’s record could contain
a field showing the pupil’s name, a field showing the pupils date of birth, and
other fields containing other information about that pupil
Queries
Queries combine information from different tables, and allow the user to
define exactly what information from these tables they wish to view.
Queries are the main questioning system in Microsoft Access. They allow
more complex questions to be asked of a number of tables. The information
contained in a query can be used as the basis for a form.
 Aston Swann 2006
5
ICDL for Educators Courseware – Database
Module 5 Part 1
Forms
Forms can be created to display the information contained in queries in an
easy to work with format. Forms can be used to view existing data from the
database, or to enter new data.
Reports
A report is an effective way to present your data in a printed format, again
using the information contained within queries.
Pages
A data access page is a special type of Web page designed for viewing and
working with data from an Internet or intranet.
Macros
A macro is a set of one or more actions that each perform a particular
operation, such as opening a form or printing a report. Macros can help you to
automate common tasks.
Modules
A module is a collection of Visual Basic for Applications declarations and
procedures that are stored together as a unit.
Note: Pages, Macros and Modules will not be covered in this course
Objects
Each part of the database described above, (tables, forms, queries, etcetera)
are known as ‘objects’ within the database.
6
 Aston Swann 2006
ICDL for Educators Courseware – Database
Module 5 Part 1
Using a Database
The following are some of the skills required to use a database:
How to add new records and delete existing records
How to search for information in the database
How to question the database
How to sort records alphabetically or numerically
How to run reports to produce simple or elaborate printouts
Toolbars
The toolbars at the top of each window in Access have different names. The
term “main toolbar” will be used to indicate the toolbar at the top of the Access
main window. From the menu bar, [View] [Toolbars] indicates the names of
the active toolbars in the Access main window.
Each object (tables, forms, queries, etcetera) within Access has its own
toolbar, showing the buttons relevant for that object.
To see alternative toolbars in the main Access window, or to close a toolbar
that is currently open on screen:
•
From the menu bar, select [View] [Toolbars]
•
Select any toolbar that does not currently have a tick next to it
To display that toolbar on screen
•
Select any toolbar that does currently have a tick next to it
To close that toolbar
 Aston Swann 2006
7
ICDL for Educators Courseware – Database
Module 5 Part 1
Example 1 – Using a database
Cool Cat(alogue)
Main database window
Form View
Table/Datasheet View
Report
8
 Aston Swann 2006
ICDL for Educators Courseware – Database
Module 5 Part 1
This example will open and use an existing database (called [CoolCat]), in
order to explore how a database can be used and to become familiar with
some of the features of Microsoft Access.
Because the database is stored on your CD drive, and it is probably not
possible to save to this drive, the first action to be taken will be to copy the file
to either your [My Documents] folder, or to another drive and folder as
appropriate. This copy of the database will then be edited, leaving the original
on the CD unchanged.
This database was created in Microsoft Access 2000. A database created in
Access 2000 can be opened and edited in either Access 2000 or Access
2002.
 Aston Swann 2006
9
ICDL for Educators Courseware – Database
Exercise 1
•
Module 5 Part 1
Opening a database
From the Taskbar, select [Start] [All Programs] [Microsoft Access]
Microsoft Access will open
The [New File] Task Pane should open at the right of the screen
If the [New File] Task Pane does not open, from the menu bar select
[View] [Toolbars] [Task Pane] to open it
•
Insert your Exercise CD into the CD drive of your PC
•
Click [More Files…]
To view the Open dialog box, giving you access to all your files
10
 Aston Swann 2006
ICDL for Educators Courseware – Database
Module 5 Part 1
Either:
To save and open a copy of the database in your [My Documents] folder
•
Click the drop down arrow to the right of the [Look In:] field and select your
CD drive
•
From the list of folders on the CD, double click on [Module 5]
•
From the list of sub-folders within [Module 5], double click on [Part 1]
To view the list of files in the [Part 1] folder
•
From the file list, click the right mouse button over the document called
[CoolCat]
•
From the quick menu, select [Send To] [My Documents]
To put a copy of the file in the [My Documents] folder
•
Click the [My Documents] button down the left of the Open dialog box
To select the [My Documents] folder in the [Look in:] field
•
Select the [CoolCat] database from the list of files
•
Click the [Open] button
To open on screen the database called [CoolCat]
 Aston Swann 2006
11
ICDL for Educators Courseware – Database
Module 5 Part 1
Or:
To save and open a copy of the database in another drive and folder
If you need to save to another folder, rather than [My Documents]:
•
Click the drop down arrow to the right of the [Look In:] field and select your
CD drive
•
From the list of folders on the CD, double click on [Module 5]
•
From the list of sub-folders within [Module 5], double click on [Part 1]
To view the list of files in the [Part 1] folder
•
From the file list, click the right mouse button over the document called
[CoolCat]
•
From the quick menu, select [Copy]
To place a copy of the database on the Windows Clipboard
12
 Aston Swann 2006
ICDL for Educators Courseware – Database
Module 5 Part 1
•
Click the drop down arrow to the right of the [Look in:] field again
•
Select the drive (and folders) containing the sub-folder in which you wish
to place the copy of the database
•
In the file list, click the right mouse button over the appropriate sub-folder
•
From the quick menu, select [Paste]
To paste a copy of the database in the selected sub-folder
•
Double click on the sub-folder in which you have placed the database copy
To view the contents of that folder
•
Select the [CoolCat] database from the list of files in the sub-folder
•
Click the [Open] button
To open on screen the database called [CoolCat]
 Aston Swann 2006
13
ICDL for Educators Courseware – Database
Module 5 Part 1
The main database window
When the [CoolCat] database opens on screen, the main database window
will be displayed.
The [Objects] pane on the left of the window shows the different parts of the
database (the tables, queries, forms, reports, etcetera); whilst the right hand
pane lists what has been created within the currently selected object.
14
 Aston Swann 2006
ICDL for Educators Courseware – Database
Exercise 2
Module 5 Part 1
Understand the database design
[CoolCat] is a database of items that are lent out. There are three tables that
hold information, or ‘records’.
Each record is contained within one row of the table. The records consist of
‘fields’, each containing one piece of data about the record.
Fields can
contain different data types, such as alphabetical, numerical, date/time. Each
field has its own ‘properties’ – which dictate such things as the amount of
information allowed in the field, any default values, validation required:
•
[tblBorrowers]
•
[tblTracking]
•
[tblItems]
 Aston Swann 2006
15
ICDL for Educators Courseware – Database
Exercise 3
Module 5 Part 1
Display the records in a form
A form provides an easy way to display on screen the records contained in
the database.
This exercise will look at a form called [frmTracking] that pulls together
information from all the tables to show who has borrowed which item on what
date.
•
Click Forms in the Objects pane in the main database window
To see the forms already created in the database
•
Click the icon to the left of [frmTracking]
•
Click the [Open] button in the toolbar
To see the Form, [frmTracking]
•
Click the [Maximise] button on the top right of the Tracking Form
window
To make the Form fill the screen
16
 Aston Swann 2006
ICDL for Educators Courseware – Database
Exercise 4
Module 5 Part 1
Viewing records
Each screen of information, representing a borrower, is called a record.
The buttons on the bottom left of the [frmTracking] window can be used to
look at other borrowers, and the item borrowed.
•
Click the [View Next] button
To see details of the next borrower
•
Click the [View Previous] button
To see details of the previous borrower
•
Click the [View First] button
To see details of the first borrower
•
Click the [View Last] button
To see details of the last borrower
•
Highlight the record number and type in a different number
To see details of that record
 Aston Swann 2006
17
ICDL for Educators Courseware – Database
Exercise 5
Module 5 Part 1
Using a form to add records
This exercise will use the [frmTracking] to add a new record to the database,
showing that someone has borrowed another CD.
•
Click the [View New] button
To display a new screen
To allow you to enter new details
•
Click the drop down arrow to the right of the [Borrow/Return] field
•
From the list shown, select [Borrow]
•
Press the [Tab] key
To be positioned in the [Date] field
•
Enter the Date as shown in the example on page 19
Tip:
Dates must either be typed as shown in the example, or as 29 May 03. Do
not use full stops (as in 29.5.03), as this will not be recognised as a date.
•
Press the [Tab] key
To be positioned in the [BorrowerNo] field
•
Type “2”
To specify that it is borrower no 2 who has borrowed the CD
To look for all the personal details for this borrower
•
Press the [Tab] key
To display details of [First Name] [Last Name] and [Form] of this
borrower
To move the cursor to the [Item No] field
•
Type “6” in the [ItemNo] field, followed by the [Tab] key
To complete all the fields for this item
Possibly, to display a blank form for the next new record
18
 Aston Swann 2006
ICDL for Educators Courseware – Database
Module 5 Part 1
If a blank new record is displayed on screen:
•
Click the [View Previous] button
To see the record that you have just completed
Tip:
As you complete each record and move to the next one, the data is saved
automatically. It is good practice to save your work every few minutes, to
prevent loss through computer crashes, etc.
Exercise 6
•
Save your work
On the “main” toolbar, click the [Save] button
As the database has already been named, this will update the existing
file
 Aston Swann 2006
19
ICDL for Educators Courseware – Database
Exercise 7
•
Module 5 Part 1
Close and open forms
From the menu bar, select [File] [Close]
To close the frmTracking window
To display the main database window in maximised view
•
In the Objects pane of the main database window, click [Forms]
To display the forms available
•
Click the icon to the left of frmCatalogue
•
Click the [Open] button
To display the frmCatalogue window:
•
If necessary, click the [Maximise] button on the top right of the
frmCatalogue window
To make the form fill the screen
20
 Aston Swann 2006
ICDL for Educators Courseware – Database
Exercise 8
Module 5 Part 1
Find information
This exercise will find all the books listed in the database.
•
Click the [View First] button
To ensure that you are viewing Record 1
As Access usually searches from the current record forwards through a
database
•
Click in the [Item Type] field
Either
•
From the menu bar select [Edit] [Find]
Or
•
Click the [Find] button in the main toolbar
To display the Find and Replace dialog box
•
Type “Book” in the [Find What] field
•
Ensure that the [Look In:] field is searching the [ItemType] field
To ensure you only search in the [Item Type] field
•
Click the [Find Next] button
To display the details of the first book
 Aston Swann 2006
21
ICDL for Educators Courseware – Database
Module 5 Part 1
To move the Find and Replace dialog box to the bottom of the window, so that
it does not obscure the displayed record:
•
Click the blue title bar of the Find and Replace dialog box
•
Hold the left mouse button down and drag the box to the bottom of the
window
•
22
Release the mouse button
 Aston Swann 2006
ICDL for Educators Courseware – Database
•
Module 5 Part 1
Click the [Find Next] button
To display the next book in the catalogue
Tip:
Each time the [Find Next] button is clicked, Access will find each of the other
books in turn, until a prompt is displayed that Access has finished searching
the records.
Tip:
This search was looking for the word “Book” in the [Item Type] field, however
the same procedure would be used to search for numbers or dates in relevant
fields.
•
Click the [OK] button
To close the prompt box
•
Click the [Close] button at the top right of the Find and Replace
dialog box
To close the dialog box
•
From the menu, select [File] [Close]
To close the frmCatalogue window
To display the main database window
•
Click the [Restore Down] button on the Title bar
To reduce the size of the main database window
 Aston Swann 2006
23
ICDL for Educators Courseware – Database
Exercise 9
Module 5 Part 1
Look at different objects and views
We have been looking at a form view of the database. Forms are contained
within the Objects pane of the database. We are now going to look at other
views available within Objects.
•
Examine the main database window
To see the different parts of a database.
To see the Objects available
The function of the different Objects is explained in the Introduction
24
 Aston Swann 2006
ICDL for Educators Courseware – Database
Module 5 Part 1
Exercise 10 View and navigate tables
This exercise will view the [tblBorrowers] table, which contains the details of
all the borrowers on the database.
All the table names in this database are preceded by the letters “tbl”. As the
database is created, it is good practice to precede table names with “tbl”,
forms with “frm”, queries with “qry” and reports with “rpt”. This will make it
easier to tell what each object is, when working with the database.
•
In the Objects pane of the main database window, click [Tables]
To display the icons representing the Borrowers, Items and Tracking
tables
•
Click the table [tblBorrowers]
•
Click the [Open] button at the top of the main database window
The [tblBorrowers: Table] window will be displayed
Each column or “field” contains one category of information
Each row represents a different person and is known as a “record”
 Aston Swann 2006
25
ICDL for Educators Courseware – Database
Module 5 Part 1
Exercise 11 Navigate records
At the bottom of the table, navigation buttons allow you to move through the
records in the table.
•
Click the [View First] button
To see details of the first borrower
•
Click the [View Previous] button
To see details of the previous borrower
•
Click the [View Next] button
To see details of the next borrower
•
Click the [View Last] button
To see details of the last borrower
•
Highlight the current record number and type in another number
•
Press [Enter]
To move to that specific record
26
 Aston Swann 2006
ICDL for Educators Courseware – Database
Module 5 Part 1
Exercise 12 Amend records – add, edit, delete within a table
Within the database, you will need to add new records as new borrowers join;
to edit details of existing borrowers; and to delete details of borrowers who
have left.
Add a new record:
•
Look for the empty row beneath the existing records that is
indicated by the [*] in the margin
•
Click in the [FirstName] field in this row
•
Type in a first name
(AutoNumber) in the [BorrowerNo] field will be replaced with the next
available number
A pen will show in the left margin, to indicate that you are editing
this record
•
Press [Tab]
To move to the [Last Name] field
•
Type in a surname
•
Press [Tab]
To move to the [Form] field
•
Select a Form name from the drop down list
•
Press [Tab] to move to the [Notes] field
As you move from field to field the data will be saved
Edit a record:
This will change Joe James’ name to Joseph
•
In the first row, double click Joe in the [First Name] Field
To highlight Joe’s name
•
Type “Joseph”
To replace Joe with Joseph
 Aston Swann 2006
27
ICDL for Educators Courseware – Database
Module 5 Part 1
Delete data in a record
• In record 3 – Penny Smith’s row – double click in the [Form] field
To highlight the entry
•
From the keyboard, press the [Delete] key
To delete the form name from Penny Smith’s record
Using the Undo command
This will ‘undo’ the deletion of Penny Smith’s form
•
Click the [Undo] button on the Standard toolbar
To replace the form name in Penny Smith’s record
Delete a record:
This will delete Penny Smith’s record
•
Click somewhere in record 3 – Penny Smith’s row
To select this record
To see an arrow in the left margin
•
From the menu bar, select [Edit] [Delete Record]
To specify that you wish to delete the record
To display a warning that this deletion will be permanent
•
Click the [Yes] button
To confirm deletion
To delete the record
To see that record number 3 is missing, showing that it has been
deleted
Tip:
If a record is linked to other records, it is not always possible to delete that
record from the database. If you attempt to delete a record that you shouldn’t,
Access will display an error message, explaining why this is not possible.
28
 Aston Swann 2006
ICDL for Educators Courseware – Database
Module 5 Part 1
Exercise 13 Filter information
In a database you can use filters to group records that share certain details.
For example, you can isolate all the records that include books.
The effects of using filters are more apparent when viewing a table.
We are currently viewing the unfiltered view of the table [tblBorrowers]. In this
exercise we will choose to see only those pupils who are in Form 8Fm
•
Click in the [Form] field in the first row
To select Form 8Fm
•
On the main toolbar, click the [Filter by Selection] button
To isolate all pupils in the database that are in 8Fm
To see how many matches have been filtered out.
 Aston Swann 2006
29
ICDL for Educators Courseware – Database
•
Look at the navigation buttons at the bottom left of the screen
To see how many records have been filtered
•
View the [FLTR] icon at the bottom right of the status bar
To show that a filter is active
•
Notice that in the main toolbar the [Remove Filter] button is
depressed
Whilst the filter is being applied.
•
Click the [Remove Filter] button
The filter will be removed
All references to [Filtered] will also be removed
All the records will be shown again
•
30
Filter out all pupils in Form 9Ty and then remove the Filter
 Aston Swann 2006
Module 5 Part 1
ICDL for Educators Courseware – Database
Module 5 Part 1
Exercise 14 Sort records
Records can be sorted alphabetically or numerically in either ascending or
descending order.
You can sort your database when using a Table or a Form.
Sorting in table view
To sort the table [tblBorrowers] on the [Last Name] field:
•
Click anywhere in the [Last Name] column
•
Click the [Sort Ascending] button on the main toolbar
To view the records arranged in ascending alphabetical order by
Surname (A to Z)
Each borrower’s details are also sorted with their names
 Aston Swann 2006
31
ICDL for Educators Courseware – Database
•
Module 5 Part 1
Click the [Sort Descending] button
To view the records sorted in descending alphabetical order by
Surname (Z to A)
Each borrower’s details are also sorted with their names
To sort the table on the [Form] field:
•
Click anywhere in the [Form] column
•
Click the [Sort Ascending] button
To view the records in ascending order by Form
•
From the menu bar select [File] [Close]
To view a warning message asking if you want to save the changes
•
Click the [Yes] button
To save the changes
To close the table view and display the main database window
32
 Aston Swann 2006
ICDL for Educators Courseware – Database
Module 5 Part 1
Sorting in form view:
This will sort the [frmTracking] form by [LastName]
•
Select [Forms] in the Objects pane in the main database window
To view the Forms currently created in the database
•
Click [frmTracking]
•
Click the [Open] button
To display [tblTracking] as a form
•
Click in the [LastName] field
•
Click the [Sort Ascending] Button on the main toolbar
To sort the records into alphabetical order
•
Click the [Next Record] button several times
To move through the records in alphabetical order of the [Last Names]
field
The [Sort Descendng] button would sort in reverse alphabetical order
For numerical fields, sorting would be in order from 0-9 or 9-0, dependent
upon whether [Sort Ascending] or [Sort Descending] was used.
•
From the menu bar select [File] [Close]
To close the Form view
To display the main database window
 Aston Swann 2006
33
ICDL for Educators Courseware – Database
Module 5 Part 1
Exercise 15 Run a report
A report is documentation that is designed for printout. It is previewed on
screen first, allowing you to check it before printing.
This exercise will look at a report that is set up in the [CoolCat] database that
prints details of who borrowed what, and when.
[rptTrackingLoans].
Run a report from the main database window:
•
In the Objects pane, click [Reports]
•
Click the Report [rptTrackingLoans]
•
On the main toolbar click the [Preview] button
The printout will be shown on the screen
•
If necessary, click the [Maximise] button
To make the window fill the screen
•
On the main toolbar click the [Zoom] button
To zoom in and out of the report
•
On the main toolbar click the [Close] button
To close the report
To display the main database window
34
 Aston Swann 2006
The report is called
ICDL for Educators Courseware – Database
Module 5 Part 1
Exercise 16 Run a query
A “query” is a tool to:
Analyse and manage information in a database
Extract specific information from a database, based on searching more
than one field and more than one table
See updated results from amended data, using queries that have been
saved
Join tables together to build forms and reports, that might use data from a
number of tables
The results of a query can be viewed on screen or printed out.
This exercise will run an existing query that combines all the fields from
[tblItems] [tblBorrowers] and [tblTracking], allowing you to see in one view the
details of who borrowed/returned a particular item.
•
Click [Queries] in the Objects pane in the main database window
•
Click the icon to the left of [qryTracking]
•
Click the [Open] button
The query window opens, displaying the fields shown on page 37
 Aston Swann 2006
35
ICDL for Educators Courseware – Database
Module 5 Part 1
The fields come from:
Borrowers Table
– Borrowers details, for example, names
Items Table
– Item No and Type
Tracking Table
– Date
This query links all this information together from the three tables, to provide
related information on one screen. This query feeds into [frmTracking], which
allows the tracking of items.
Without this query you would have to look at the three different tables
separately to see all the related information.
It is, however, helpful to have these separate, linked tables for the different
items, as the smaller tables are easier to manage. Also, linking the
information can avoid duplication of data and can cut down on data entry time.
(In our current database, for example, the Items information only has to be
entered once for each Book/CD/etc, and then for each borrower, the
information about the item borrowed can be picked up from this linked Items
table without the need for re-entry of the data.)
36
 Aston Swann 2006
ICDL for Educators Courseware – Database
Module 5 Part 1
 Aston Swann 2006
37
ICDL for Educators Courseware – Database
Module 5 Part 1
Primary key
Each table has a primary key field.
The primary key is a field that uniquely identifies each record stored in the table.
The primary key field is usually a number.
As an example, in the Items table, [ItemNo] is a primary key. Every item in the
table has a unique [ItemNo]. This will ensure that if the database contains
details of two copies of the same book, each copy will have a unique [ItemNo]
and can therefore be monitored separately.
Primary key fields are used when linking tables to create queries. For example,
the table called [tbleTracking] contains the [ItemNo] field.
The table called
[tblItems] also contains the [ItemNo] field and, in this table, it is the primary key
field. A query combining records from the [tbleTracking] and [tblItems] tables
can match up the [ItemNo] of each record in the [tbleTracking] to the record in
the [tblItems] containing the same [ItemNo].
In this way, Access can show
which item has been borrowed on each occasion.
38
 Aston Swann 2006
ICDL for Educators Courseware – Database
Module 5 Part 1
Exercise 17 Relationships between tables
This exercise will look at all 3 tables to view the relationships between them
created by the primary key fields.
•
Ensure that the [qryTracking] is still open on screen
•
From the menu bar select [Tools] [Relationships]
To see the three tables
•
Scroll through the tables
To see that they are linked by the primary key fields in the [tblItems] and
[tblBorrowers] tables
To see the primary key fields displayed in bold
To view the lines linking the common fields [ItemNo] and [BorrowerNo]
The Tracking table therefore can track which borrower has borrowed what
item. Further details on the borrower can be pulled from the Borrower’s table.
Further details on the Item can be pulled from the Items Table.
•
Click the [Close] button at the right of the Relationship title bar
To close the Relationship window
•
From the menu bar select [File] [Close]
To close the table view
To display the main database window
 Aston Swann 2006
39
ICDL for Educators Courseware – Database
Exercise 18 Close a database and Access
Close the database
•
From the menu bar, select [File] [Close]
To close the database
To leave Microsoft Access open on screen
Close Access:
•
40
From the menu bar, select [File] [Exit]
 Aston Swann 2006
Module 5 Part 1
ICDL for Educators Courseware – Database
Module 5 Part 1
Example 2 – Creating a database
This example will create a database in Microsoft Access including tables, forms,
a query and a report.
Exercise 19 Design and plan a database
Before creating a database, the following should be considered:
What is the purpose of the database?
What detail do you want from it for information on screen or on printouts?
What information are you going to put into it?
How are you going to capture this information?
The answers to these questions will affect the structure of the database. You
will need to plan:
What tables you will need
What fields to include
What will the fields hold – numbers, letters, dates etc
What will be the primary key field in each table
How will the tables be linked
What other database objects you need to design to achieve the required
output, for example forms, queries and reports
 Aston Swann 2006
41
ICDL for Educators Courseware – Database
Module 5 Part 1
Once you have decided what you need in your database, you then need to
design the method of collecting the information, also known as data capture.
Some things to consider about data capture are:
How to ensure information is accurate and relevant
How to minimise duplication and error (“Garbage In, Garbage Out”)
Access forms can be used on screen to capture data. The forms can guide
people to enter the information required accurately, for example by providing a
drop down list – with a list of options.
Alternatively, paper forms can be designed. The following is an example of a
paper data capture form. It directs users to correctly enter information on paper
so that it can be typed accurately into the database.
Application for CoolCat Membership
First Name:
Surname:
Form:
Date of Birth:
/
/
Parent/Guardian:
First Name:
Surname:
Contact Number:
42
 Aston Swann 2006
ICDL for Educators Courseware – Database
Module 5 Part 1
We are going to create a database of pupils with their hobbies.
The purpose of this database is to:
Produce a form on screen to track pupils and their attendance at their hobby
sessions
Produce a printout
Produce a report listing pupils and sessions attended
There will be three tables:
A table of pupils [tblPupil]
A table of hobbies [tblHobby]
A table of sessions [tblSession]. This tracks which pupil does which hobby
and their attendance (one pupil can have more than one hobby)
The three tables will contain:
As can be seen by the links above, the following fields will link the tables:
The [HobbyCode] Field
– links the Hobby Table to the Session Table
The [PupilNo] Field
– links the Pupil Table to the Session Table
 Aston Swann 2006
43
ICDL for Educators Courseware – Database
Module 5 Part 1
In order for users to input the information easily, we will create the session
attendance form shown below.
44
 Aston Swann 2006
ICDL for Educators Courseware – Database
Module 5 Part 1
Exercise 20 Create a database
•
From the Taskbar, select [Start] [All Programs] [Microsoft Access]
Microsoft Access will open
The [New File] Task Pane should open at the right of the screen
If the [New File] Task Pane does not open, from the menu bar select
[View] [Toolbars] [Task Pane] to open it
•
In the [New] field, click [Blank Database]
To display the [File New Database] screen
 Aston Swann 2006
45
ICDL for Educators Courseware – Database
Module 5 Part 1
Within the File New Database dialog box, you will specify the name and location
for the database:
•
In the [File Name:] field, type [Hobbies]
Either
•
Click the [My Documents] button down the left of the Save As dialog box
To select the [My Documents] folder in the [Save in:] field
Or
•
Click the drop down arrow to the right of the [Save In:] field
To view the available drives and folders
•
Select the drive, folder (and sub-folders) in which you wish to save the
document
•
Click the [Create] button
To save the Hobbies database into the selected folder
To open [Hobbies : Database], ready to create a table
46
 Aston Swann 2006
ICDL for Educators Courseware – Database
Module 5 Part 1
Exercise 21 Create tables
This exercise will use the Table wizard to create a Pupils table.
The wizard will provide some sample tables with ready-made fields. We will
need to choose which fields we want for our database, and then to rename
some of the fields so that their names fit better with our database.
•
Click [Create table by using wizard]
•
Click the [Open] button in the Hobbies : database main database
window
The Table wizard dialog box will be displayed
•
Select [Business] from the field on the left
 Aston Swann 2006
47
ICDL for Educators Courseware – Database
Module 5 Part 1
Selecting fields
•
In the [Sample Tables:] field scroll down and select [Students]
To display a suggested list of sample fields
•
In the [Sample Fields:] list click [StudentID]
•
Click the [Insert One Field] button
To insert [StudentID] into the [Fields in my new table:] field
To select [StudentID] as a field for the new database
•
Similarly select and insert:
[FirstName]
[LastName]
[PhoneNumber]
[ParentsNames]
So that all these fields are displayed in the [Fields in my new table:] field
48
 Aston Swann 2006
ICDL for Educators Courseware – Database
Module 5 Part 1
Renaming a field:
•
Select [StudentID] in the [Fields in my new table:] field
•
Click the [Rename Field…] button
The Rename field dialog box opens
•
Type in “PupilNo”
Ensure that you do not insert any spaces or non alpha-numeric
characters
•
Click the [OK] button
•
In the same way rename:
[LastName] to [Surname]
[PhoneNumber] to [ContactNo]
[ParentsNames] to [ParentGuardian]
Tip:
Renaming can also be used to correct errors in field names
 Aston Swann 2006
49
ICDL for Educators Courseware – Database
Naming the table
•
Click the [Next] button
To display the option to name the table:
•
Enter the name [tblPupil] in the top field
To name your table
•
Select [Yes, set a primary key for me]
To let the wizard set the primary key
•
Click [Next]
• Select [Enter data directly into the table]
•
Click the [Finish] button
To display the empty [tblePupil] table
50
 Aston Swann 2006
Module 5 Part 1
ICDL for Educators Courseware – Database
Module 5 Part 1
PupilNo
The PupilNo is an Autonumber.
Microsoft Access automatically numbers each pupil as you enter their details.
You will not be able to enter anything in this field. At a later date, you could
change the field type if you wished to amend the numbers yourself.
You may experience some problems entering phone numbers. Don’t worry!
The field will be modified later to deal with this.
Enter pupil details
We will type in the details of at least five pupils shown on the list below
•
Click in the [FirstName] field, in row 1
•
Type in “Jack”
Either
•
Press [Tab] to move to the [Surname] field, in row 1
Or
•
Click with the mouse in the [Surname] field, in row 1
•
Type in “Simmons”
•
Press [Tab] or click in the [ContactNo] field, in row 1
•
Type in “0121 787 7632”
•
Press [Tab] or click in the [ParentGuardian] field, in row 1
•
Type in “Mrs Simmons”
•
Press [Tab] twice or click in the [FirstName] field, in row 2
 Aston Swann 2006
51
ICDL for Educators Courseware – Database
•
Repeat for the remaining pupils, entering at least five
•
Click the [Save] button in the main toolbar
To double check that the data is saved
52
 Aston Swann 2006
Module 5 Part 1
ICDL for Educators Courseware – Database
Module 5 Part 1
Exercise 22 Change viewing mode
Objects in the database can be viewed in 2 ways:
Datasheet view – where the individual records are displayed in table or
form view
This is the view that has been used so far in this example
Design view – where the fields in the object can be amended.
This view will be used to modify the fields in the Hobbies database
Switching between the Datasheet view and Design view is done using the [View]
button on the main toolbar, as will be shown in the next exercise.
 Aston Swann 2006
53
ICDL for Educators Courseware – Database
Module 5 Part 1
Exercise 23 Modify field types
This will change the format of the [ContactNo] by amending the [Input Mask]
field. If the [ContactNo] field in your table has not automatically been given an
input mask by the table wizard, you will not need to make this amendment.
However, it will still be useful to see how an input mask works, and how you
could add one to fields in the future.
An input mask controls how data is stored in a field (for example, automatically
putting the dialling code into brackets, or specifying the correct number of letters
or digits to be used in a field).
•
Click the [Design View] button on the main toolbar
To display the table in design view
To list the Field Names in the [Field Name] column
The [Data Type] column explains what kind of information is being held in
each field
•
Click each field
To see the information in the Field Properties field at the bottom of the
screen change for each field
•
Click the [ContactNo] field
•
In the Field Properties field at the bottom of the screen, click into the [Input
Mask] field
To see a sample of how numbers should be displayed in this field
54
 Aston Swann 2006
ICDL for Educators Courseware – Database
•
Module 5 Part 1
Click the button to the right of the [Input Mask] field
To view details about input masks
•
Click [Yes] on the warning message that opens
To save the table before opening the Input Mask wizard dialog box
•
In the Input Mask wizard dialog box, click the [Next] button
To go through the screens of the dialog box, to get an idea of how input
masks work
•
When you have looked through the screens, click [Cancel]
To close the Input Mask wizard dialog box without making any changes
•
In the Input Mask field in the [tblPupil] table, delete all the text in the field
To remove the Input Mask from the [Contact No] field
To remove the brackets from the phone numbers
•
Click the Save button in the main toolbar
To save the amended table design
 Aston Swann 2006
55
ICDL for Educators Courseware – Database
•
Module 5 Part 1
Click the [Datasheet View] button in the main toolbar
To view the changes
•
If necessary, click in each Phone number in the [ContactNo] column
To amend the phone numbers
56
 Aston Swann 2006
ICDL for Educators Courseware – Database
Module 5 Part 1
Exercise 24 Add a field
This exercise will add a [DateOfBirth] field to the table.
•
Click the [Design View] button in the main toolbar
To change to design view
•
Click in the margin to the left of [ContactNo]
To select the whole row
•
From the menu bar, select [Insert] [Rows]
To insert a new row above [ContactNo]
•
Click the blank row in the [Field Name] column
•
Type in “DateOfBirth”
To name your new field
•
Click in the [Data Type] column in the [DateOfBirth] row
•
Click the drop down arrow
To display all the possible types of data
•
Select [Date/Time]
To change the data type to a date
 Aston Swann 2006
57
ICDL for Educators Courseware – Database
Module 5 Part 1
Exercise 25 Add descriptions to help with data entry
Guidelines or descriptions associated with any field can help anyone entering
information and using the database.
Add a description explaining the use of the [ContactNo] field
•
In the Description column, click in the [ContactNo] row
•
Type in “This number is for emergencies and general communication”
•
Click the [Save] button in the main toolbar
To save the amended data table
•
Click the [View Datasheet] button
To review the revised table
•
Click in one of the [ContactNo] fields
To view the Description in the Status Bar at the bottom of the screen
•
58
Enter the [DateOfBirth] for the existing pupils as shown in the table below
 Aston Swann 2006
ICDL for Educators Courseware – Database
•
Enter details of two more pupils
•
For each pupil, click in the [ContactNo] column
Module 5 Part 1
To view the prompt that is displayed in the status bar at the bottom of the
screen for this column
•
From the menu bar, select [File] [Close]
To close the table [tblPupil]
Tip:
The information that you enter is saved automatically.
 Aston Swann 2006
59
ICDL for Educators Courseware – Database
Module 5 Part 1
Exercise 26 Create a table using design view
The Pupils table was created using the Table wizard. This exercise will use
Design view to create a Hobbies table, showing what hobbies are available, run
by which staff and in what location.
•
In the Objects pane of the main database window, select [Tables]
•
Click [Create table in Design View]
•
Click the [Open] button in the main database window
To display a new table in design view
60
 Aston Swann 2006
ICDL for Educators Courseware – Database
Module 5 Part 1
Exercise 27 Create fields
• In the [Field Name] column, type in the field names as shown below
 Aston Swann 2006
61
ICDL for Educators Courseware – Database
Module 5 Part 1
Exercise 28 Amend data types
This exercise will amend the Data Type for the [HobbyCode] field to
[AutoNumber], so that the code numbers will be automatically incremented
when new hobbies are entered.
•
In the [HobbyCode] row, click in the [Data Type] column
•
Click the down arrow
To display the choice of data types
•
Select [AutoNumber]
To automatically insert incremental numbers in this field
62
 Aston Swann 2006
ICDL for Educators Courseware – Database
Module 5 Part 1
Exercise 29 Create a lookup column
A lookup column gives the user a list of choices when data is entered into a
field. This gives control to the database designer over what the user can enter
into this field in the future.
•
Click in the [Data Type] column in the Location row
•
Click the down arrow
To display the choice of data types
•
Select [Lookup Wizard…]
The Lookup Wizard dialog box is displayed
•
Click [I will type in the values that I want]
•
Click the [Next] button
 Aston Swann 2006
63
ICDL for Educators Courseware – Database
Module 5 Part 1
The Lookup wizard will display a form, ready to type in the entries you require.
•
Leave the [Number of columns:] as 1
•
In Column 1 type “School”
A new row will be inserted below
•
[Tab] to the next row
•
Type “Sports Centre”
•
[Tab] to the next row
•
Type “Youth Centre”
•
Click the [Next] button
•
Leave [Location] as the name of the lookup column.
•
Click the [Finish] button
To complete creation of the lookup details
64
 Aston Swann 2006
ICDL for Educators Courseware – Database
Module 5 Part 1
Exercise 30 Create a primary key field
This exercise will make the [HobbyCode] field the primary key field for the
Hobbies table, and thus give a unique identity to each record that is entered.
•
Click the [HobbyCode] field
•
From the menu bar select [Edit] [Primary Key]
•
To insert the Primary Key symbol to the left of [HobbyCode]
•
Click the [Save] button in the main toolbar
•
To open the Save As dialog box:
•
Type [tblHobby]
•
Click the [OK] button
To save the table as [tblHobby]
 Aston Swann 2006
65
ICDL for Educators Courseware – Database
Module 5 Part 1
Exercise 31 Enter the records
This exercise will look at the table in datasheet view, so that you can enter the
hobby records.
•
Click the [Datasheet View] button on the main toolbar
To display the empty table
To type in the information:
•
The [HobbyCode] field will be numbered automatically
•
In row 1, click in the [Hobby] field
•
Type “Football”
•
Press the [Tab] key or click in the [Staff] field in row 1
•
Type “Fi”
•
In row 1, click the drop down arrow in the [Location] field
•
Click [Sports Centre]
To select this location from the available list
To complete the entry of this record
•
Using the information in the table below, repeat the above procedure, to
enter the details for at least five records
•
From the menu bar select [File] [Close]
To close the Hobbies Table
•
66
If asked, [Save] the table
 Aston Swann 2006
ICDL for Educators Courseware – Database
Module 5 Part 1
Exercise 32 Create the session table
The Session table will detail which pupils attended which hobby sessions, on
which date.
This table will be created in design view
•
Click [Tables] in the Objects pane of the main database window
•
In the right hand pane, click [Create table in Design view]
•
Click the [Open] button in the main database window
To display the table in design view
 Aston Swann 2006
67
ICDL for Educators Courseware – Database
Module 5 Part 1
Entering the field names and data types
•
Enter the field names as shown in the table below
•
Enter the Data Types as shown below
•
Click in the [Completed?] field
•
In the Field Properties field at the bottom of the screen, click the [Lookup] tab
•
Click the drop down arrow to the right of the [Display Control] field
•
Select [Text Box] from the available options
To make the [Completed] field give the option of typing [Yes] or [No]
•
Use the [Primary Key] button on the main toolbar to make
[SessionNo] the primary key field
•
68
Use the [Save] button on the main toolbar to save the table as [tblSession]
 Aston Swann 2006
ICDL for Educators Courseware – Database
Module 5 Part 1
Exercise 33 Amend field format
The format used for fields can be amended as required.
Date format
This will show the options available for date fields
•
Click in the margin to the left of [DateAttended]
To select that row
•
In the Field Properties field at the bottom of the screen, click into the
[Format] field
•
Click the drop down arrow to the right of the field
To view the date formats available
•
Select the date format you would like to use for your field
•
[Save] the changes to the [tblPupil] table
 Aston Swann 2006
69
ICDL for Educators Courseware – Database
Module 5 Part 1
Number format
There are also various number formats available.
•
Click in the margin to the left of [PupilNumber]
To select that row
•
In the Field Properties field at the bottom of the screen, click into the
[Format] field
•
Click the drop down arrow to the right of the field
To view the number formats available
•
View the different number formats available for your field
•
Click the drop down arrow to the right of the [Format] field again
To close the list of options without changing the selection for this field]
Tip:
You should also be aware that making a number format smaller might result in
the loss of data already contained in a cell, as any data longer than the new
value will be discarded.
70
 Aston Swann 2006
ICDL for Educators Courseware – Database
Module 5 Part 1
Field size
There are also several options available for field sizes. However, if the field you
wish to amend is linked by relationships to fields in other tables, the size cannot
be changed.
As with number format changes, existing data may be lost in the table if the field
size is changed to a smaller value than is already contained within records in the
table.
•
Click in the margin to the left of [HobbyCode]
To select that row
•
In the Field Properties field at the bottom of the screen, click into the [Field
Size] field
•
Click the drop down arrow to the right of the field
To view the number formats available
•
Leave the selected field size as [Long Integer]
•
Click the drop down arrow to the right of the [Field Size] field again
To close the list of options without changing the selection for this field
 Aston Swann 2006
71
ICDL for Educators Courseware – Database
Module 5 Part 1
Error messages
As mentioned above, if the field you wish to amend is linked by relationships to
fields in other tables, the size cannot be changed. If you attempt to change the
field size in such an instance, the following will happen:
•
An error message will open, stating that the field size cannot be changed
because of the relationship with other tables
•
Click [OK]
To close the error message box
•
Ensure that in the field, the field size is left as it was previously
Entering the records
•
Click the [Datasheet View] button
To display the empty table
•
Enter the records as shown in the table below
•
From the menu bar, select [File] [Close]
To close the table
To return to the main database window
72
 Aston Swann 2006
ICDL for Educators Courseware – Database
Module 5 Part 1
Exercise 34 Link the tables
The datasheet view in the Session table is not very “user friendly”. For example,
it does not explain the hobby codes, or which number represents which pupil.
This exercise will therefore create “relationships” between the 3 tables
([tblHobby] [tblSession] and [tblPupil]). The relationships will link the tables, in
order that matching information from each table can be ‘joined together’ and
displayed on screen in a meaningful way.
Either
•
Select [Tools] [Relationships] from the menu bar
Or
•
Click the [Relationships] button in the main toolbar
The [Relationships] window will open
The Show Table dialog box will be displayed on top
•
Select each table in turn from the Show Table dialog box, and click the [Add]
button
To display the tables in the [Relationships] window
•
Click the [Close] button
To close the Show Table dialog box
 Aston Swann 2006
73
ICDL for Educators Courseware – Database
Module 5 Part 1
Positioning the tables to link
Moving the tables around in the Relationships window will make it easier to link
the tables as required.
•
Select one of the fields in the [tblPupil] table
•
Click the title bar of the [tblPupil] table
•
Drag the table to the position shown in the diagram below
•
Repeat for the other 2 tables
To arrange the tables in the order shown below
•
If any of the tables have scroll bars to their right (meaning that they are too
short to view all the fields contained in them), move the mouse pointer to the
bottom of that table and click and drag the lower edge of the table down
To make the table longer
To enable all the fields to be viewed at the same time
74
 Aston Swann 2006
ICDL for Educators Courseware – Database
Module 5 Part 1
Relationship types for linked tables
When fields are linked, a Relationship Type between the 2 fields will be created.
There are 3 different relationship types:
One-To-One
In a one-to-one relationship, each record in the first table
can have only one matching record in the second table,
and each record in the second table can have only one
matching record in the first table. One-to-one relationships
are not very common, because most information related in
this way would be contained within one table.
One-To-Many
A one-to-many relationship is the most common type of
relationship. In a one-to-many relationship, a record in the
first table can have many matching records in the second
table, but a record in the second table has only one
matching record in the first table.
Many-To-Many
In a many-to-many relationship, a record in the first table
can have many matching records in the second table, and
a record in the second table can have many matching
records in the first table.
This exercise will create One-To-Many relationships between the [tblSession]
table and the [tblHobby] and [tblPupil] tables.
However, the same procedure would be used to create the other relationships
between tables. As an example, a one-to-one relationship would be created if
the primary fields from two tables were linked – as in each table each record in
the primary field has to be unique
 Aston Swann 2006
75
ICDL for Educators Courseware – Database
Module 5 Part 1
Validity of relationships
Relationships between tables have to adhere to certain rules in order that they
are valid. There are 3 main rules to consider when linking tables in Access:
•
The primary key field should be the linked field from the primary table (for
example, [PupilNo] should be the linked field in the [tblPupil] table. Any
alternative field used should have a unique index.
•
The linked fields should usually contain the same data type.
•
Both tables should be contained in Access databases that are currently open
on screen when the links are created.
Once tables have been linked, it could cause problems if records from one table
were deleted that were linked to records in another table. For example, if a
pupil’s record were deleted after that pupil had been entered into the Session
table as attending a session, the Session table would be invalid.
To ensure the validity of links, and to prevent linked records being deleted,
“Referential Integrity” can be applied when creating relationships between
tables.
Referential integrity sets the following rules for linked tables:
•
You cannot, for example, assign a non-existent pupil number to a session
(however, you can have a session created with no pupils registered as
attending)
•
You cannot, for example, delete a pupil’s record if that pupil is assigned to a
session
•
You cannot, for example, change a pupil’s [PupilNo] if that pupil is assigned
to a session
The ability to apply referential integrity will be presented as the relationships
between the tables are being created.
76
 Aston Swann 2006
ICDL for Educators Courseware – Database
Module 5 Part 1
Create the links and view the relationships:
•
Click and hold the [HobbyCode] field in [tblHobbyl]
•
Drag the mouse to the [HobbyCode] field in [tblSession]
•
Let go of the mouse button over the [HobbyCode] field in [tblSession]
The Edit Relationships dialog box will open
The [tblHobby] table will be shown on the left
The [tblSession] table will be shown on the right
•
Look at the [Relationship Type:] field at the bottom of the dialog box
The Relationship Type will show One-To-Many
This means that for every hobby there can be several sessions
Don’t forget that a one-to-one relationship would be created if there could
only be one matching record in each table
•
Click the [Create] button
To create this link between the [tblHobby] and the [tblSession]
•
Click and hold the [PupilNo] field in [tblPupil]
•
Drag the mouse to the [PupilNo] field in [tblSession]
•
Let go of the mouse button over the [PupilNo] field in [tblSession]
The Edit Relationships dialog box will open
The [tblPupil] table will be shown on the left
The [tblSession] table will be shown on the right
 Aston Swann 2006
77
ICDL for Educators Courseware – Database
•
Module 5 Part 1
Look at the [Relationship Type:] field at the bottom of the dialog box
The Relationship Type will show One-To-Many
This means that every pupil can attend several sessions
•
The [Enforce Referential Integrity] field can be ticked
To ensure the validity of the relationship, as discussed above
•
Click the [Create] button
To create this link between the [tblHobby] and the [tblSession]
To display all the linked tables:
•
Click the [Save] button
To save the relationships
•
Click the [Close] button at the right of the Relationship Title bar
To close the Relationships window
78
 Aston Swann 2006
ICDL for Educators Courseware – Database
Module 5 Part 1
Exercise 35 Create a query
Having linked the tables, it is now possible to create a query to pull together
information from the records in some or all of the tables. The query can then be
used as the basis for a form to show which pupils attended which sessions for
which hobby.
Be aware that, although this query is using information from several tables, the
same procedure would be used to create queries where the information was
picked from just one or two tables.
This query will be created using the query wizard.
•
In the Objects pane of the main database window, click [Queries]
•
Click [Create query by using wizard]
•
Click the [Open] button on the Database toolbar
To display the Simple Query Wizard dialog box
 Aston Swann 2006
79
ICDL for Educators Courseware – Database
Module 5 Part 1
Selecting the tables and fields to use
•
Click the drop down arrow in the [Tables/Queries] field
•
Select [Table: tblSession]
The fields in this table will be displayed in the [Available Fields:] field
•
Click the [Insert all Fields] button
All the fields will be moved into the [Selected Fields:] field
•
Click the drop down arrow in the [Tables/Queries] field
•
Select [tblHobby]
The fields in this table will be displayed in the [Available Fields:] field
•
Click the [Insert all Fields] button
To move all the fields into the [Selected Fields:] field
•
In the [Selected Fields:] field, click [tblHobby.HobbyCode]
•
Click the [Remove One Field] button
To remove this duplicated field from the [Selected Fields:] field
It is duplicated because it exists in the [tblSession] table also
To leave all but this field in the [Selected Fields:] field
80
 Aston Swann 2006
ICDL for Educators Courseware – Database
•
Click the drop down arrow in the [Tables/Queries] field
•
Select [tblPupil]
Module 5 Part 1
The fields in this table will be displayed in the [Available Fields:] field
•
Avoiding the [PupilNo] field, which has already been inserted
from the [tblSession] table, select each field in turn and click the
[Insert One Field] button
To insert all but the [PupilNo] field into the [Selected Fields:] field
To complete insertion of all the fields required from all 3 tables
Naming the query
•
Click the [Next] button
•
Select the [Detail (shows every field of every record)] option
To have all fields displayed in the query
•
Click the [Next] button
•
In the [What title do you want for your query] field type
“qrySession”
To replace the name that is given to your query
To rename the query “qrySession”
 Aston Swann 2006
81
ICDL for Educators Courseware – Database
•
Select [Open the query to view information]
So that you will view the completed query when it is created
•
Click the [Finish] button
To open the qrySession : SelectQuery screen
•
From the menu bar, select [File] [Close]
To display the main database window
To list the new query in the Query pane
•
Click qrySession
•
Click the [Open] button
To display the query details again
•
From the menu bar, select [File] [Close]
To close the query
82
 Aston Swann 2006
Module 5 Part 1
ICDL for Educators Courseware – Database
Module 5 Part 1
Exercise 36 Create a form
This exercise will create a form that can be used to enter details of the pupil and
hobby applicable to each session.
If you get an error message “subscript out of range” whilst creating your form,
cancel out of the form and follow the procedure set out in the section below
entitled “If you get an error message whilst creating your form:
•
In the Objects pane of the main database window, click [Forms]
To see the available forms and options
•
Click the [New] button
The New Form dialog box will open
 Aston Swann 2006
83
ICDL for Educators Courseware – Database
Module 5 Part 1
Selecting the form type
•
Select [AutoForm: Columnar]
To automatically create a form in column format, using the data contained
in the query you will specify next
•
Click the down arrow to the right of the [Choose the table or query where the
object’s data comes from:]
•
Select [qrySession]
•
In order to pick the data from the [qrySession] query
•
Click the [OK] button
To display the form
To see the details for the first session that is contained in the
[qrySession] query
84
 Aston Swann 2006
ICDL for Educators Courseware – Database
Module 5 Part 1
If you get an error message whilst creating your form:
•
Cancel out of your form
•
In the Objects section of the main database window, select [Forms]
•
Double click the icon to the left of [Create form by using wizard]
To display the Form Wizard
•
Click the [Cancel] button
•
Try to create an AutoForm again
Once your form has been created
With the first record shown on screen in the form:
•
Click the [Save] button
To display the Save As dialog box
•
In the [Form Name:] field type “frmSession”
•
Click [OK]
To save the form
 Aston Swann 2006
85
ICDL for Educators Courseware – Database
Module 5 Part 1
Exercise 37 Enter data using the new form
This exercise will enter and amend the details for a new session record. It will
also delete a record.
Enter a new record
•
Click the [New Record] button at the bottom of the form
To display the next new record
The [SessionNo] will be numbered automatically
•
Click in the [PupilNo] field
•
Type “4” and press the [Tab] key
To pull in details of pupil number 4
•
In the [HobbyCode] field, type “3”
To pull in details of hobby code 3
•
Click in the [DateAttended] field
•
Type [20/6/03]
•
Click in the [Completed?] field
•
Type [Yes]
To complete the details for this session
86
 Aston Swann 2006
ICDL for Educators Courseware – Database
Module 5 Part 1
Edit the record
•
Click in the [PupilNo] field and highlight the number there
•
Type [3] and press the [Tab] key
To change the pupil details for this record
Tip:
Be aware that, at present, it is possible to change any of the fields in the form in
this way. If this happened, it would obviously mean that the pupil or hobby
details would not add up. In order to prevent this happening, those fields that
are automatically populated should be ‘locked’. This will be covered in Part 2.
•
Click the [New Record] button
To display the next new record
•
Type in the [PupilNo] [HobbyCode] and [DateAttended] details for a new
record
To enter the details for another session record
 Aston Swann 2006
87
ICDL for Educators Courseware – Database
Module 5 Part 1
Delete the record
•
With the record still on screen, click in the margin down the left of the form
To select the entire record
•
From the keyboard, press the [Delete] key
An error message will open, warning that deleting a record cannot be
undone
•
Click [Yes]
To delete the record
•
From the menu bar, select [File] [Close]
To close the form
To display the main database window
88
 Aston Swann 2006
ICDL for Educators Courseware – Database
Module 5 Part 1
Exercise 38 Previewing and printing
Information can be previewed and printed from a table, a form, a query or a
report.
Printing from tables, forms and queries is fine for simple printouts, but for more
elaborate printouts, reports should be used.
Previewing and Printing from a table
• In the Objects pane of the main database window, select [Tables]
•
Click [tblHobby]
• Click the [Open] button
To display the Hobby table
•
Click the [Print Preview] button, in the main toolbar
To preview the Table
To view the current layout of the table on screen
 Aston Swann 2006
89
ICDL for Educators Courseware – Database
•
Module 5 Part 1
On the main toolbar, click the [Print] button
To print out the table to your currently selected printer
•
On the main toolbar, click the [Close] button
To close the preview screen
To display the table again
•
From the menu bar, select [File] [Close]
To close the table
To display the main database window
Printing a query
A query can be previewed and printed out in the same way as shown above for
a table, after selecting and opening the query from the main database window.
Printing a form
A form can also be previewed and printed out in the same way, once it has been
selected and opened from the main database window. However, forms do not
always fit neatly on the page by default, and it is preferable to amend the page
setup for the form before printing it. This will be covered in a later exercise.
90
 Aston Swann 2006
ICDL for Educators Courseware – Database
Module 5 Part 1
Exercise 39 Create a report
The advantages of creating a report for printouts are:
More than one table and query can be used in each report
The whole database can be used in the report
You have more control over what is printed in a report
Customised headers, footers and page numbers can be added.
Create a report using the wizard
•
In the Objects pane, of the main database window, select [Reports]
•
Double click [Create report by using wizard]
To display the Report Wizard dialog box
 Aston Swann 2006
91
ICDL for Educators Courseware – Database
Module 5 Part 1
Selecting the fields to use
The report can be based on fields contained within tables, queries, or a
combination of both.
As a query will probably contain fields from more than one table, it will give you
access to more fields at one time, and save working your way through a variety
of tables. However, the process to be carried out if tables were used would be
identical to that explained below for using queries.
•
From the Tables/Queries drop down list, select [Query: qrySession]
•
Click [FirstName]
•
Click the [Insert One Field] button
The field will be inserted into the [Selected Fields] field
•
Insert each of the following fields in turn into the [Selected Fields] field
[Surname]
[Hobby]
[DateAttended]
[Completed?]
Tip:
The order of the fields here affects the order of the fields in the report
•
92
Click the [Next] button
 Aston Swann 2006
ICDL for Educators Courseware – Database
Module 5 Part 1
Selecting how to view the data
•
In the [How do you want to view your data?] field, click [by tblPupil]
To view the information pupil by pupil
•
Click the [Next] button
•
Do not group your information. Leave this screen as it is
 Aston Swann 2006
93
ICDL for Educators Courseware – Database
Module 5 Part 1
Sorting the data in the report
This will sort the data by each hobby, in order of the date attended, showing
completed and non-completed records separately
•
Click the [Next] button
•
Click the drop down arrow to the right of the first field
•
Select [Hobby]
To sort the information by hobby
•
Click the drop down arrow to the right of the second field
•
Select [Date Attended]
To sort each hobby by date attended
•
Click the drop down arrow to the right of the third field
•
Select [Completed?]
To further sort each hobby by whether it is completed
Tip:
Clicking the [Ascending] button to the right of any of the fields, would change the
order in which records were displayed for that field from Ascending (0-9, A-Z) to
Descending (9-0, Z-A)
94
 Aston Swann 2006
ICDL for Educators Courseware – Database
Module 5 Part 1
Selecting the report layout and style
•
Click the [Next] button
•
Select the [Align Left 1] layout
To display your information as shown in the example
•
Click the [Next] button
•
Click [Compact]
To select the style of your report
 Aston Swann 2006
95
ICDL for Educators Courseware – Database
Module 5 Part 1
Naming and completing your report
•
Click the [Next] button
•
Type “rptPupil” as your title for this report
•
Select [Preview the report]
So that the report is previewed on screen when you have finished
creating it
•
Click the [Finish] button
To display the Print Preview screen
To preview your report
To automatically save the report
•
Click on the report
To zoom in and out
96
 Aston Swann 2006
ICDL for Educators Courseware – Database
Module 5 Part 1
Tip:
Modifications to Reports, such as changing the fields displayed; changing field
locations; adding colour, logos and clipart will be covered in later modules.
•
From the menu bar, select [File] [Close]
To close the saved report
To display the main database window
 Aston Swann 2006
97
ICDL for Educators Courseware – Database
Exercise 40 Closing Access
To close Access and the database:
•
From the menu bar, select [File] [Exit]
To close the database
To close Access
98
 Aston Swann 2006
Module 5 Part 1