Sei sulla pagina 1di 68

I

n ternationa INTERNATIONAL

l
COMPUTER
Com p

IC

ce
DL
DRIVING
cen
ut

er Li
D riving ã LICENCE ã

MODULE 5

Databases / Filing Systems

Comprehensive Study Guides


covering
ICDL Syllabus, version 4

ã 2004 The European Computer Driving Licence Foundation Ltd

ã 2004 The Computer Society of Zimbabwe & World Links Zimbabwe


• Database – Module 5 •

TABLE OF CONTENTS

INTRODUCTION ................................................................................. 3
Purpose of this Study Guide ........................................................ 3

DATABASE CONCEPTS ...................................................................... 5

FIRST STEPS WITH DATABASES ..................................................... 11


Opening a Database Application ............................................... 11
The Microsoft Access Environment ............................................ 12
Closing Microsoft Access ........................................................... 14
Using Help ................................................................................ 14
Close an Object (i.e. a Table, Query or Report) ......................... 18
Close a Database File ............................................................... 19
Adjust Basic Settings/ Changing View Modes ............................ 19
Modify the Toolbar Display ........................................................ 21

MAIN OPERATIONS .......................................................................... 22


Creating and Saving a Table ...................................................... 22
Finding a Record Based on Given Criteria ................................. 26
Defining Keys ............................................................................ 27
Setting up an Index .................................................................... 28
Updating a Database ................................................................ 29
Table Design/Layout .................................................................. 31

USE OF FORMS ................................................................................ 37


Creating a Form ........................................................................ 37
Entering Data into a Database Using a Form ........................... 39
Modify Form Layout .................................................................. 40
Arrangements of Objects in Form Layout ................................. 42
Importing an Image or Graphic File into a Form ....................... 43

• © Computer Society of Zimbabwe ICDL Training Materials • 1


• Database – Module 5 •

RETRIEVE INFORMATION ................................................................. 46


Basic Operations ...................................................................... 46
The Query Form ....................................................................... 46
Create a Simple Query .............................................................. 47
Adding Filters ............................................................................ 52
Refine a Query .......................................................................... 53
Select and Sort .......................................................................... 54

WORKING WITH REPORTS .............................................................. 56


Creating and Saving Reports Based on Tables/Queries ............. 56
Grouping Data and Using Report Totals .................................... 58
Modifying a Report .................................................................... 61
Creating Headers and Footers .................................................. 63
Customizing Headers and Footers ............................................ 65
Deleting a Report ....................................................................... 66

PREPARING OUTPUTS ..................................................................... 67

2 • © Computer Society of Zimbabwe ICDL Training Materials •


• Database – Module 5 •

INTRODUCTION
This study guide is part of the complete set of World Links training material
which includes:
Phase O: Computer Literacy (seven modules)
Phase I: Introduction to the Internet for Teaching and Learning
Phase II: Introduction to Telecollaborative Learning Projects
Phase III: Curriculum and Technology Integration
Phase IV: Evaluation and Diffusion of Technological Innovations
Phase V: Planning for School-Based Telecenters
Phase VI: The World Of ICT: A Seminar for Policy Makers

Purpose of this Study Guide


This study guide is intended to assist candidates preparing to undergo
testing for the fifth module of the International Computer Driving Licence.
It covers the theoretical background for “Module 5 Database” which requires
the candidate:
x To understand the basic concepts of databases
x To demonstrate the ability to use a database on a personal computer
x To design and plan a simple database using a standard database
package
x To demonstrate the ability to retrieve information from an existing
database by using the query, select and sort tools available in the
database
x To be able to create and modify reports.

• © Computer Society of Zimbabwe ICDL Training Materials • 3


• Database – Module 5 •

PRACTICAL EXERCISES
There are practical exercises that the user should attempt after every section
of the study guide. The exercises are designed to meet the requirements of
the ICDL test. For ease of recognition, the exercises have all been put into
boxes like the one below.

Exercise

TIPS

The study guide will also contain tips, to help shed light on some
of the instructions.

4 • © Computer Society of Zimbabwe ICDL Training Materials •


• Database – Module 5 •

DATABASE CONCEPTS
A database is an organised store of information constructed around a
particular theme. It consists of a series of rows (called records in Access)
and columns (fields)
For instance, a business might use a database to store information about
sales and stock inventories. A doctor might search a database to find
information about particular medical symptoms.
How you organise information in a database depends on how you intend
to use it. So a doctor might use one kind of database to find information
about each patient’s symptoms, and the doctor's receptionist might use a
different kind to store personal details and financial records of patients.
In addition to making it easier to retrieve information, databases can serve
as a tool for analysing information. You can use a database to find patterns
and trends in large volumes of data that are otherwise hard to detect. In
businesses and scientific research this is often a key function of databases.
A database is made up of tables, queries and reports. The tables contain
the data. The queries contain instructions on how the information is to be
retrieved, and the reports contain layouts to dictate how the retrieved
information will be printed. Each table is made up of records and each
record contains fields that relate to that record.
Each different table, query or report within the database file is called an
object. An object that has been opened is termed an active object.
Hence the hierarchy is:
x A field is a single item/fact such as First Name, Surname, Date of
Birth, etc.
x A record is a collection of fields
x A table is made up of a group of records
x An object is a table or a query or a report (as necessary to extract
information from the table)
x A database is made up of objects. It may contain several tables, and
the related queries and reports

• © Computer Society of Zimbabwe ICDL Training Materials • 5


• Database – Module 5 •

DATA TYPES
When creating a database you need to know the type of data you are
going to enter into the database. For example, are you going to enter text,
numbers or dates?
Data Type Description
Text This is the default type for all new fields. Text fields can contain
up to 255 characters and may include letters, numbers and
symbols. In cases where the data contains more than 255
characters, then you will need to use the Memo data type.
Memo Memo type fields are used to keep information such as notes,
comments or explanations. They hold up to 64 000
characters of alphanumeric data.
Number These are numeric fields and are used to store only numbers
that will be used to perform calculations. Performance of
the database will be better if numbers that are for
identification/information only and will not be used in
calculations are stored as text. Numbers are stored in any
one of five fixed sizes:
x Byte size from 0 to 255 without decimals, occupying
1 byte
x Integer Size is from -32, 786 to 32 767 without decimals,
occupying 2 bytes
x Long Integer size is from -2 147 483 648 to 2 147 483 647
without decimals occupying 4 bytes
x Single Size is up to 38 digits, with or without decimals,
occupying 4 digits
x Double size takes up to 398 digits with or without decimals
and occupies 8 bytes
Date/Time These fields contain date and time formats. Date fields can
be used for calculations such as age. It should be noted
that date/time fields have their width being set automatically.
Examples of some formats are short date, long date, general
date, short time etc.
Currency Used to store currency data in a special fixed format with
four decimal places to prevent rounding errors. Currency
entered can be up to 15 digits.

6 • © Computer Society of Zimbabwe ICDL Training Materials •


• Database – Module 5 •

AutoNumber This is a numeric value that is entered automatically by


Microsoft Access each time a new record is added.
Numbering begins at one for the first record entered and
increments by one for each following record.It is
recommended that an autonumber field must always be
used to number the records
Yes or No These are for logical fields in Access and can contain only
one of two values , 1 for Yes and 0 for No. The format property
allows the user to display the field as Yes/No, True/False, or
On/Off.
OLE Object The fields may contain a graphic or an object from another
application supporting OLE (Object Linking and
Embedding).
Lookup The Lookup Wizard creates a lookup column, which displays
Wizard a list of values from which one value may be selected.
It is required in Access 2002 that a primary key field must be set. The
primary key is a field that is used to uniquely identify each record. Thus
the contents of the field must be unique for each record. E.g. an
autonumber field will be unique for each record and can be used as a
primary key.
To view all indexes in a table, Choose View, Indexes (in Table Design view).

TYPES OF DATABASES
Databases are usually structured according to one of the following models:
x The hierarchical model
x The network model
x The relational model
The hierarchical model is organised in terms of parent-child relationships.
The hierarchical model is also known as the tree model because it follows
an inverted tree-like structure. This means that you can access several
child records from a single parent record. And child records can be grouped
according to parent records.
The network model simply extends the hierarchical model by allowing
more flexible linkages between parent and child objects. For instance, a
child record may have more than one parent record.

• © Computer Society of Zimbabwe ICDL Training Materials • 7


• Database – Module 5 •

The network and hierarchical models are suitable for information that is
organised in a predetermined and fixed structure. These models are used
in products such as CD-ROM-based encyclopaedias.
The relational database model is used when data needs to be organised in
a flexible manner. Records in a relational database can be grouped in many
different ways according to specific needs. In a relational database you
can construct queries that retrieve data that is grouped in meaningful ways.
For instance, you might use a database that has information about turnover
and geographical location. By constructing a query, you can extract turnover
statistics for a particular geographical location from the database.

TABLES
In a relational database, data is described using two-dimensional tables.
Tables consist of columns and rows. Columns are used to list the various
attributes of data. Rows are used to contain the individual records
So in a table that contains information about customers, you might have
columns for:
x Names
x Telephone numbers
x Postal addresses
Each customer that is entered into the Customers table is a record. Rows
are generated whenever a record is captured into a table. Each row consists
of fields that correspond to the different columns. So one might refer to the
Names field in the Customers table.
A flat-file database consists of a single table. For instance, you can think of
a Microsoft Excel spreadsheet as a flat-file database.
A relational database consists of several tables. Tables in a relational
database are related to each other by shared columns.
So the Names column in the Customers table might also be a column in
the Sales table. This allows you to construct queries that link records in the
Customers table to records in the Sales table.
Relational databases can be constructed and maintained using a relational
database management system (RDBMS). Microsoft Access provides an
extremely flexible environment within which to design databases, allowing
you to change your basic design over time.

8 • © Computer Society of Zimbabwe ICDL Training Materials •


• Database – Module 5 •

PLANNING YOUR DATABASE


Even so, carefully planning your database from the start can save you
time and expense in the long run. It helps to have a clear idea of what tasks
you want your database to perform. You might create a list of the main
functions you want your database to fulfil.
If other people are going to be using your database, you should ask them
what sort of information they would like to get from the database. As you
gather information about the functions of the database that you are
designing, you may well discover that some tasks are dependent on others.
For instance, obtaining up-to-date figures on profit margins in a company
is likely to depend on information about turnover and operational costs
being entered accurately. Creating flow diagrams that describe the
relationships between the different elements in your database helps you in
the design process.
As part of the initial planning process, you need to identify the data elements
from which your database will be constructed. You need to define what
data is needed for each task that your database performs – this is called
input data. And you need to ensure that the information generated by a
task – known as output data – is what you expect. A data element may be
output data in one context and then used as input data elsewhere in your
database.
You can then begin to develop the specifics of your database design by
planning which tables you are going to use. Each table should contain
information about one subject rather than several subjects. Information
should not be duplicated within a table. And information should not be
duplicated across tables unnecessarily.

F IELDS
While planning your tables, you need to decide on the fields you will use in
each table. Fields should break down information into its smallest logical
parts. So instead of having a single field for addresses, you might have a
field for postal codes, another for street addresses, and a third field for
telephone numbers.
It's not usually a good idea to include data that has already been processed
in your table. So you should try to avoid creating columns that contain
totals derived from existing fields. It's more efficient to build derived data
into your database when you create reports.

• © Computer Society of Zimbabwe ICDL Training Materials • 9


• Database – Module 5 •

Fields should be as directly related to the table's subject as possible. So


sales-related information should be included in a Sales table rather than
an Employees table.
It's a good idea to include an ID field for a table containing a discrete
number for each record. For example, each employee's record in an
Employees table would have its own Employee ID. ID fields are useful
when you create relationships between tables.

RELATING TABLES IN A DATABASE


Once you have decided on the tables that you need in your database, you
need to define relationships between the tables. Otherwise you have little
more than a collection of spreadsheets, rather than a relational database.
Relationships between tables allow you to run complex queries against
multiple tables in a database, providing you with greater insight into the
data in your database. For instance, a database might have a Customers
table, a Sales Region table, and a Sales table.
You would be able to construct a single query to obtain a list of customers
in a specified region that would include details of the sales made to each
customer.
In order to create relationships between tables, you must define a primary
key for each of your tables. A primary key is a field or set of fields that
contains different data for each record in your table. ID fields consisting of
discrete numbers automatically assigned to each record are often used as
primary keys.
Let's say that in a Customers table you have defined the Customers ID
field as the primary key. And let's say that the Customers ID field is also a
field in a table called Sales. The Customer ID field in the Sales table is
called the foreign key and you can create relationships between the fields
in the Sales and Customers tables by using the primary and foreign keys.

10 • © Computer Society of Zimbabwe ICDL Training Materials •


• Database – Module 5 •

FIRST STEPS WITH DATABASES


This section will concentrate on opening the Microsoft Access program
using the Start button, although there are several other methods of doing
this.

Opening a Database Application


1. Click on the Start button
2. Point to Programs 2
3
3. Click on Microsoft Access
After opening the Microsoft Access program
the following window appears with a dialog box 1
prompting the user to choose to create a new
database using:
x Blank Access Database, OR
x Access database
wizards, pages, and
projects, OR
x Open an existing
database file.
This diagram shows
some of the existing files
(under More Files… ) that
can be opened on
starting the Microsoft
Access program for the
computer where this
picture is derived from.
To open a particular file,
click on the filename and
then on OK.

• © Computer Society of Zimbabwe ICDL Training Materials • 11


• Database – Module 5 •

Note that if you choose the Blank Access Database, you will be taken to
the File New Database window, which prompts you to provide a name
for the database.

The Microsoft Access Environment


The Microsoft Access window has the features that are found on other
Microsoft application windows, that is:
x The Caption or Title bar
x The three main buttons being the Minimising , Maximising and Close
buttons found on the far right side of the title bar
x The Menu bar
x The Tool bar
x The Status bar.
These have been dealt with in detail in all other ICDL modules. The other
features of a database window are:

The use of the tabs was covered in Module 2. As a recap, the tab in use
appears raised higher/is different from the rest. In this diagram, the selected
tab is Tables. To select a different tab, just click on the tab.

12 • © Computer Society of Zimbabwe ICDL Training Materials •


• Database – Module 5 •

THE DATABASE TITLE BAR

This shows the name of the database that is in use and minimise, maximise
or restore and close buttons for that database window are displayed on
the far right side of the bar.

THE DATABASE CONTROL MENU


This, like other control menus, contains the following options,
Restore, Size, Move, Minimise, Maximise and Close. When the
database window is maximised this icon is displayed on the menu bar
near the File menu.

OBJECTS TAB

Use this tab to view the desired objects such as Tables, Queries, Forms,
Reports etc. Once you choose a tab a list of objects will be displayed, from
which you can select the desired one.

OBJECT LIST BOX


This box displays
the list of objects in
each tab. For
example, in the
diagram below
there is only one
object for the Forms
tab and this is
"Enter Student
Information".
"Enter Student
Information" is the
object name that
identifies the object
and controls its
function.

• © Computer Society of Zimbabwe ICDL Training Materials • 13


• Database – Module 5 •

Closing Microsoft Access


There are several ways of closing the Microsoft Access program, using:
x The Close button
x The Program control menu
x The File menu, and selecting Exit
x The keyboard, pressing ALT and F4 simultaneously.
The easiest method is to simply click on the Close button.

Using Help
No matter how proficient one can become with using any package, there
are times when there is need to use the help features.
All Office packages come with a help facility. In Microsoft Access (as in
other Office programs) there is an Office Assistant that can answer
questions, offer tips and provide help for the feature selected.

14 • © Computer Society of Zimbabwe ICDL Training Materials •


• Database – Module 5 •

USING THE SEARCH FACILITY FROM THE OFFICE ASSISTANT


1. Click the Office Assistant
2. From the Office Assistant
balloon, type sort in the text box
for the What would you like
to do window and then click on
Search
(Various help topics associated
with the phrase appear)
3. From the help topics that
appear, click on Sort
records in a report
You can then read the help
information relating to the
topic
4. On point 1 of the Sort
records in a report help
window, click on Design
view
(An explanation or definition of the green-coloured dash underlined
word/phrase is given)

HOW TO USE THE CONTENTS AND INDEX TO GET HELP


Just like a textbook, the program contains its own contents page and index.

WHAT TYPE OF HELP CAN I GET FROM THE CONTENTS AND


INDEX COMMAND?
The contents and index command of the Help menu allows you to search
for help in three ways:
The Contents tab allows you to browse through topics category by category.
To see the help topics in each category you will need to double click the
category or click the Display command button.

• © Computer Society of Zimbabwe ICDL Training Materials • 15


• Database – Module 5 •

Double-click on a category
such as this one to see the
help topics that go with it.

Help topics that go with the


Working with data category
are displayed

The Index tab allows you to see a list of index entries, just scroll through
the list to see entries that do not fit into the screen. This option is also
flexible in that it allows you to search for entries faster by giving you the
option of typing the word (or first few letters of it) you are looking for.
The Find tab can be used to search for words or phrases that may be
contained in a particular Help topic.
1. Click on Help
1
2. Select Contents and Index
2
3. Make sure that the Index tab is selected.
4. Type sa (for save) in the textbox as we
would like to search for help on how to
save in Access.
(Notice that as the first few characters
of the phrase are typed it moves to help
5 on words starting with sa…)
5. Select using toolbar button for the index
5 entry we want help on
Notice that the particular topic's name
6
3 is written in the text box for the word
we are looking for
6. Click the Display button so that you are
able to see the help topic associated
with saving using the toolbar button

16 • © Computer Society of Zimbabwe ICDL Training Materials •


• Database – Module 5 •

WHEN TO USE THE WHAT'S THIS FACILITY OF HELP


This feature is used when there is a need to know what a particular icon
does or to understand what an option in a dialog box stands for.
1. Click on Help
1
2. Select What's This
OR press Shift+F1
3. Click on an icon and a 2
description of what it does
appears.

The What's This icon is also a very useful tool to make of use
when one is using dialog boxes. If there is an option in the dialog
box that you do not understand, click the What's This icon from
the dialog box's title bar and click on the option to see the help
topic pertaining to the option.

Just as all textbooks have a contents page of what they contain, the
Windows Help facility is
no exception.
1. Click on Help 1
2. Select Contents
and Index
2
3. Click on the
Contents tab to
select it

• © Computer Society of Zimbabwe ICDL Training Materials • 17


• Database – Module 5 •

4. From the list of topics that appear all you need to do is to double-click
on the icon of the major category containing the help topic you want
5. Select the help topic you want from the list that appears.

4
5

Click on the Display command button to view the help information


associated with the topic selected.

Close an Object (i.e. a Table, Query or Report)


There are three ways of closing an active object, either by using the file
menu, the program control menu or a specific combination of keystrokes.

METHOD 1 USING THE FILE MENU


1. Click on File
2. Click on Close

METHOD 2 USING THE CONTROL MENU


Double click on the Object's control menu

METHOD 3 USING THE KEYBOARD


Press Ctrl and W keys simultaneously

18 • © Computer Society of Zimbabwe ICDL Training Materials •


• Database – Module 5 •

Close a Database File


Remember that you are not closing the Microsoft Access program, you
are closing the database file.
1. Click on File on the menu bar
2. Click on Close
After closing the database file the window's working area will be "greyed
out" indicating that there is no open database.

Adjust Basic Settings/ Changing View Modes


After a table has been opened, data from that table may be viewed in one
of two ways, that is either in datasheet view or form view. When using
datasheet view, the data is displayed in rows and columns and when it is
viewed in form view data is displayed one record at a time, according to
the form design specified within that database.

WHAT DO THESE TWO DIFFERENT VIEWS LOOK LIKE?

A datasheet is made up of fields and records. Records are in rows and


fields in columns. In both views there are navigating buttons. All the records
will have the same number of fields. Each field will have a field name. In the
example the field names are Enter Student ID, Name, Surname, Class
and Date of Birth. A record number on the navigating buttons will represent
the current record being viewed.

• © Computer Society of Zimbabwe ICDL Training Materials • 19


• Database – Module 5 •

THE DATASHEET WINDOW VIEW

FIELD NAME

RECORD
FIELD ITEM

NAVIGATING BUTTONS

HOW TO MOVE WITHIN A VIEW


The navigating buttons are used to move around in the table, both in the
datasheet view and the form view. These buttons are used by clicking on
them. Displayed below are the buttons and their functions, also displayed
on the navigating buttons are, the current record position and the number
of records within the table. For example in this case there are 5 records
and the current record is record 1.

TOTAL NUMBER
OF RECORDS IN A
TABLE

CURRENT
RECORD CLICK TO ADD A
CLICK HERE TO GO NEW RECORD
TO FIRST RECORD

CLICK TO GO TO CLICK HERE TO GO


NEXT RECORD TO THE LAST
CLICK TO GO TO THE
RECORD
PREVIOUS RECORD

HOW TO GO TO A SPECIFIC RECORD


For example how can one go directly from record 2 to record 5? This is
done by pressing the F5 key, typing the number of the desired record and
then pressing the enter key.

20 • © Computer Society of Zimbabwe ICDL Training Materials •


• Database – Module 5 •

Modify the Toolbar Display


1. Click on View 1
2. Select Toolbars
The toolbars with ticks beside them 2
are the ones currently displayed on 3
the screen
3. Click on Table (Datasheet)
The tick disappears and the is
removed from the screen
4. Move the cursor to a blank area of the
visible toolbars. 6
5. Right-click on a blank portion of the
toolbar area
The toolbars menu pops up
6. Click on Table (Datasheet)
The Table Datasheet toolbar re-appears on the screen
7. Move the cursor to the left edge of the Table Datasheet toolbar. Drag
it to the centre of the screen. A toolbar not positioned below the menu
bar is said to be floating.
If you no longer want the toolbar on the screen, click its Close button
when it is floating.
8. Drag it back to the top, making sure that you move it to the position
occupied by the Formatting (Datasheet) toolbar
Note that the Table Datasheet toolbar is not hidden behind the
Formatting (Datasheet) toolbar as would have happened in Microsoft
Word, Excel or Powerpoint.

• © Computer Society of Zimbabwe ICDL Training Materials • 21


• Database – Module 5 •

MAIN OPERATIONS
Creation of a database requires a valid reason for doing so and some of
the steps to be taken have been explained in previous ICDL modules.
Planning steps should involve making decisions on:
x What data will be stored
x Where the data will come from
x Validation rules for data entry
x Which unique data field will be used as the primary key
x An appropriate filename for the database
x Where (i.e. in which folder) the database will be stored.

RULES FOR FIELD NAMES


May consist of a maximum of 64 characters
Can contain spaces, a hyphen or a semicolon
A period is not allowed
Assign preferably short field names
Do not include too many field names in one table. Rather use more than
one related table (relational database)
Refer to the database concepts section to refresh your memory on data
types.

Creating and Saving a Table

CREATING A NEW DATABASE WHEN THE MICROSOFT ACCESS


PROGRAM HAS NOT YET BEEN OPENED
1. Open the Microsoft Access program
2. Click on the Blank Access database radio button
3. Click on the OK button
The File New Database window appears
4. Type a name for the Database in the File name text box
5. Click the Create button

22 • © Computer Society of Zimbabwe ICDL Training Materials •


• Database – Module 5 •

CREATING A NEW DATABASE AFTER MICROSOFT ACCESS HAS


ALREADY BEEN OPENED

1. Click on File
2. Click on New …
The New Dialog Box appears
3. From the New dialog box, click on the Database icon
4. Click on OK
5. Type a name for the database in the File name text box
6. Click the Create button

Exercise: Creating an Empty Database


1. Click on the Start button
2. Point to Programs
3. Click on Microsoft Access
4. Click on Blank Database
The new file database dialog box appears
5. On file name, type the name of the database as
Studentdata
6. Click on the Create button
At this stage the database has been created but it is just an
empty database without any objects. The next task is to
create a table where you will store the student information

CREATING A TABLE
In the following exercise, the table to be created should contain fields
appropriate to store each student's:
x File number
x First name
x Surname
x Date of birth
x Home town

• © Computer Society of Zimbabwe ICDL Training Materials • 23


• Database – Module 5 •

Exercise: Creating a Table within a Database


1. Select the Create table in Design View option if it is not
already selected and then click the Open button
Alternatively you can double-click on the option or click
on the Design icon from the toolbar
2. Type the Field Name of each field in turn (Hint, the first
field is called Student File No)
3. Press the Tab key to move to the Data Type column, or
alternatively click on the cell.
4. By default, Text is the selected type. Should you require a
different data type, click on the cell. From the drop-down
list, select the appropriate data type. Continue to enter the
other fields and types as follows:
Name ; Text (data type)
Surname ; Text
Date of Birth ; Date/Time
Town ; Text
5. Click on the Save icon
The save as dialog box appears. Alternatively, if you click
on the Close button for the table, you will also get to the
Save As dialog box.
6. Type the name of the table as Student Information
7. You will be prompted to choose a primary key. For now we
will not create a primary key. Click on the No button.Notice
that the title bar of the Design View window has changed
to display [Student Information : Table]
8. Close the Design View window using its Close button.

ENTERING DATA INTO A TABLE


Data may be entered into a table either in datasheet view where all other
records are visible, or in form view one record at a time.
After opening a table, the insertion point or blinking cursor will be displayed
in the first field. Start typing the data you want in the field. To move to the
next field press the tab key once or click in the next field.

24 • © Computer Society of Zimbabwe ICDL Training Materials •


• Database – Module 5 •

The following exercise will lead you into entering data into the table that
was created in the previous exercise.

Student Name Surname Date of Town


File No Birth
0001 Joramu Banda 19/08/73 Gweru
0002 Justin Mupinda 21/07/74 Chinhoyi
0003 Portia Kavai 14/01/76 Harare
0004 Kudzai Kumirai 24/08/78 Chinhoyi

Exercise: Entering Data in a Table


1. Click on the Table tab
2. Click on Student Information
3. Click on the Open button or double-click on the table's name
to open it
4. Type the data given above exactly as given in each of the
fields as indicated
Depending on your computer's Regional Settings for dates,
either the month or the day will come first. As an activity,
ensure that the dates are as in the table above.
5. Press the Enter key after each record has been keyed in
6. Click on the Save button to save the information
7. Close the datasheet by clicking on the Close button

Exercise: Viewing a Datasheet


1. Click on the Tables tab
2. Click on Student Information
3. Click on the Open button
4. Maximise the Datasheet window
5. Click on the row containing the First record
6. Click on the row containing the Last record
It should read Record 4 of 4 at the bottom of the page
7. Press the F5 key and type 3 for the record number at the
bottom of the screen. Press Enter (What Happened?)
8. Close the Datasheet View

• © Computer Society of Zimbabwe ICDL Training Materials • 25


• Database – Module 5 •

Finding a Record Based on Given Criteria

Exercise: Finding a Record


1. Open the Student Information table
2. Click the Find button
Alternatively from the Edit menu, select Find…
3. Type Kavai in the Find What: text box.
4. Click the Find First button
You can continue clicking the Find Next button to search
the rest of the table for the item. Microsoft Access will then
inform you that the search item no longer has further
occurrences.
5. Click the Close button
6. Close the Student Information table and then open it again.
7. Click on Edit
8. Select Replace…
9. In the Find What text box type Kavai
10. In the Replace With text box type Banda
For the Look In: drop-down list, it is advisable to select the
Table in case the word you are looking for may not be in he
current column. This way Access can look in all the fields
for your word.
11. Click the Replace All button
This means that any field that contains Kavai will be replaced
with Banda.
12. Click on the Yes option to acknowledge the warning from
Microsoft Access
13. Repeat steps 7 to 12 to find Kumirai as a surname and then
replace it with Mupinda.
14. Click the Find and Replace window's Close button.
You will notice that the file will be automatically updated.

26 • © Computer Society of Zimbabwe ICDL Training Materials •


• Database – Module 5 •

Defining Keys

WHAT IS A PRIMARY KEY?


A primary key is a field or fields that uniquely identifies one record from
another. It is characteristically a value that will not be duplicated in two
different records. In the database you have created the first column contains
a student file number. This is unique for each student whereas other fields
may contain same information. For example in your table the field Town
contains the same data (Chinhoyi) in Justin's and in Kudzai's records.

HOW DO YOU DEFINE A PRIMARY KEY?


This has to be done in design view rather that datasheet view.

Exercise: Assign the Student File No Field as the


Primary Key
1. Open the Studentdata database and select the Student
Information table
2. Click on the Design button (to open the table in design
view)
3. Click on the Student File No field if it is not already selected
4. Click on Edit
5. Select Primary Key, OR after step 4 Click on the Primary
Key button When a Field has been defined as a Primary
key, the key sign will appear beside the field name
6. Save changes

The key sign shows that the


Student File No is a primary
key for the Student Information
table.

• © Computer Society of Zimbabwe ICDL Training Materials • 27


• Database – Module 5 •

Setting up an Index
An index is used in Microsoft Access to find and sort records. Microsoft
Access uses indexes in a table as you use an index in a book to find required
chapters. It looks up the location of the data in the index. You can create
indexes based on a single field or on multiple fields. Multiple-field indexes
enable you to distinguish between records in which the first field may have
the same value.

HOW TO DECIDE WHICH FIELDS TO INDEX

You will probably want to index:


x Fields that you search frequently
x Fields you sort, or
x Fields that you join to fields in other tables in queries
It is important to note that indexes can slow down some action queries
such as append queries, when the indexes for many fields need to be
updated while performing these operations.
The primary key of a table is automatically indexed, and you cannot
index a field whose data type is Memo, Hyperlink, or OLE Object. For
other fields, you should consider indexing a field if all the following apply:
x The field's data type is Text, Number, Currency, or Date/Time
x You anticipate searching for values stored in the field
x You anticipate sorting values in the field
x You anticipate storing many different values in the field. If many of the
values in the field are the same, the index may not significantly speed
up queries

CREATING A SINGLE-FIELD INDEX


1 Open a table in Design view
2 In the upper portion of the window, click the field for which you wish to
create the index (refer to the following figure)
3 In the lower portion of the window (portion for field properties), click
the Indexed property box

28 • © Computer Society of Zimbabwe ICDL Training Materials •


• Database – Module 5 •

4 Click the down-arrow next to it and select Yes (Duplicates OK) or


Yes (No Duplicates)
Select the Yes (No Duplicates) option if you want to ensure that no
two records have the same data in this field.

Updating a Database
Each time that any additional records are added into any of the tables
within the database, if changes are made to table properties, or additional
objects such as queries and reports inserted, the database file should be
saved.

It is useful, when developing a new database to keep previous


versions as security copies.

1. Open the Student database so that you can be able to open the
Student Information table
2. Click on the Add New record button ( ) from the navigating
buttons at the bottom of the Access screen
The navigating button now shows that the table has 5 records
3. Add a new record with the following field details:
TM06 ; Tanatswa ; Colin ; 21/12/2001, Chinhoyi

• © Computer Society of Zimbabwe ICDL Training Materials • 29


• Database – Module 5 •

4. Go back to the field for Surname in the new record and delete Colin
replacing it with Mupinda
Your record should now have the information similar to that given
below:
TM06 Tanatswa Mupinda 21/12/01 Chinhoyi
The rules as for deleting text in Microsoft Word apply when deleting
data in a table.
5. Click on Edit (after making sure that the row selector is in record 5 as
this is the record to be deleted. If it is not, click on any field in the
record or in the row selector button to select record 6)
6. Select Delete Record
7. Click the OK button to confirm you want to delete the record
OR instead of steps 5 and 6, with the record to be deleted selected,
click the Delete Record button ( )
Another way is to click the row selector button for record 5 so that it is
selected. Simply press the Delete key on the keyboard!
Notice that you cannot undo a deletion of a record
8. Go to Record 2 and change the name Justin to Munyaradzi
9. Click the Undo button or from the Edit menu, select Undo
10. You will notice that the full text of the Student File No field is not visible
Go to the Format menu, select Column Width…
11. You can either type in a new column width or better still, use the Best
Fit button which changes the size of the column to accommodate the
largest entry in the column OR instead of steps 10 to 11, you can
double-click the column selector cross hair between the Student File
No. and Name fields.

Moving Columns
12. Click on the Town field button to select the whole column
13. Move the cursor to the button area and ensure it is tilted
14. Drag to the line between Surname and Date of Birth columns to move
the column to this new selection
15. Save changes and close the table

30 • © Computer Society of Zimbabwe ICDL Training Materials •


• Database – Module 5 •

TO DELETE A TABLE, FORM OR QUERY


This can only be done from the Database window.
Select the table or object that you want to delete.
Press the Delete key from the keyboard OR right-click and then select
Delete.

PRINTING A TABLE
Printing is just the same as with all the other packages. One of the things
to highlight is that you can choose to print certain record.

Table Design/Layout

MODIFYING FIELD ATTRIBUTES


One example is going to be given as the standard way of changing some
field attributes.

Consequences of Changing Field Size Attributes


Data types can be altered after entering records, but data might be lost if
the data types are not compatible. Compatible data types will be converted,
but it is time consuming and slows up the saving process of the data.
Smaller field sizes can be processed faster and require less memory. Thus,
use the smallest possible field size but make sure that the field width is
adequate to accommodate the entered data.
The assigned field name does not determine the width of the field
In this study guide we will concentrate on creating a simple database with
only one table.

CHANGING THE FIELD SIZE FOR TEXT AND NUMBER FIELDS


Use this procedure to control the maximum number of characters that
can be entered into a text field or the range and kind of numeric values that
can be entered into a number field.
1. In Table Design view, in the upper portion of the window, click the
field whose Field Size property you want to set

• © Computer Society of Zimbabwe ICDL Training Materials • 31


• Database – Module 5 •

2. In the lower portion of the window, click the Field Size property box
For a text field, type the maximum number of characters to allow in the
field (up to 255).

CREATING VALIDATION RULES


A validation rule is an expression that limits the values that can be entered
in a field.
The maximum length for the ValidationRule property setting is 2048
characters.
Field validation rules can't contain references to other fields.
Microsoft Access automatically validates values based on a field's data
type; for example, Microsoft Access doesn't allow text in a numeric field.
You can set rules that are more specific by using the ValidationRule
property.
If you set the ValidationRule property but not the ValidationText property,
Microsoft Access displays a standard error message when the validation
rule is violated. If you set the ValidationText property, the text you enter is
displayed as the error message.
Below are some examples of validation rules.

ValidationRule property Meaning


Like "J?????" Entry must be 6 characters and begin
with the letter "J"
Between 01/01/60 And Any date from 1960 to 1985 is valid.
31/12/85 This could be permissible date of births
for a company's employees.
Between 60000 And Means that only values from A$60 000
900000 to $900 000 may be entered
>= #1/1/04# And Only dates in 2004 may be entered
<#1/1/05#

This is how the input looks like in the Design view window for the currency
example.

32 • © Computer Society of Zimbabwe ICDL Training Materials •


• Database – Module 5 •

Note that where you do not add validation text, as done above, the general
error message is the one that appears. It is good practice to enter your
own validation text so as to make your table more user-friendly.
Using these examples, create a table to test each of the data types. As an
example, for the currency field enter values such as $59 999, $60 000,
$500 000, $900 000, $901 000, $1 000 000. In other words, enter values
at the limits, in-between the limits, outside the limits as well as just outside
the limit to test.

TYPES OF RELATIONSHIPS
Microsoft Access allows you to link tables using the following types of
relationship:
x One-to-one
x One-to-many
x Many-to-many
x Many-to-one
A one-to-one relationship allows you to link each record in one table to a
single record in another table. One-to-one relationships can be used to
break up tables that have a large number of fields. Although one-to-one
relationships are the simplest kind of relationship, they are not that common
because it's usually easier to use a single table. In order to create a one-to-
one relationship between two tables, you must use fields that are primary
keys to link the tables.
A one-to-many relationship allows you to link each record in one table to
several records in another table. For instance, each employee entered into
the Employees table might be linked to a large number of records in the

• © Computer Society of Zimbabwe ICDL Training Materials • 33


• Database – Module 5 •

Sales table. But each sale that generates a record in the Sales table is
linked only to a single record in the Employees table.
In a one-to-many relationship, only one of the fields being linked can be a
primary key. The primary key must be located in the table that contains
one record for the many records in the other table. So in the case of the
Employees and Sales table, the Employees table holds the primary key.
Many-to-one relationships are useful when updating multiple records that
are linked to a single value in another table – such as Employees from a
particular region.
A many-to-many relationship between two tables allows you to create one-
to-many relationships from either table. So if you have a table for clients
and a table for sports, you can link several sports to a single client. And
you can link several clients to a single sport, such as golf. Or you can
retrieve several records from the Sports table for several clients.

JUNCTION TABLES
To create a many-to-many relationship between two tables, you need to
create a third table, called a junction table. This table will contain a primary
key with at least two fields – one for each foreign key from the tables that
you are relating. One-to-many relationships are created to the junction
table from the tables to join them in a many-to-many relationship.
Let's create a diagram of tables and relationships for a database called
Customer Orders that is needed by Award Sportswear.
You start by gathering information on the purpose of the database. After
interviewing a range of employees at Award Sportswear, the following
information needs in relation to the Customer Orders databases are
identified:
x Information on each customer's payment record
x Records of which products particular customers order
You start by deciding what tables to create, and in this case they are:
x A Customers table
x An Orders table
x A Products table
x A Payment table

34 • © Computer Society of Zimbabwe ICDL Training Materials •


• Database – Module 5 •

You now determine appropriate fields for each table, informed by your
earlier research into the needs of employees at Award Sportswear. You
decide to create an ID field for each table to serve as the table's primary
key. You start by determining relationships from the central table – in this
case the Orders table. One customer can place several orders, but each
order is placed by a single customer. So you define this as a one-to-many
relationship as shown.
Because some orders are paid off in instalments but each instalment is for
a single order, you define a one-to-many relationship between the Orders
table and the Payment table. Each payment is for a particular order. Several
different products can be ordered in a single order. And each product can
be ordered many times. So you need to create a many-to-many
relationship between the Products table and the Customers table. In order
to create a many-to-many relationship between orders and products, you
create a junction table called Order Details.
The primary keys of both the Orders and the Products table are included
in the Order Details primary key.
You can also include fields in the junction table that are not included in the
Orders and Products tables, such as Quantity.

DATABASE MANAGEMENT SOFTWARE


Microsoft Access is the Microsoft Office suite's relational database
management system (RDBMS). It allows all levels of users to create their
own databases with relative ease while making use of powerful database
tools.

What is Referential Integrity?


Referential integrity is a system of rules that Microsoft Access uses to ensure
that relationships between records in related tables are valid, and that you
don't accidentally delete or change related data. You can set referential
integrity when all of the following conditions are met:
x The matching field from the primary table is a primary key or has a
unique index.
x The related fields have the same data type. There are two exceptions.
An AutoNumber field can be related to a Number field with a FieldSize
property setting of Long Integer, and an AutoNumber field with a

• © Computer Society of Zimbabwe ICDL Training Materials • 35


• Database – Module 5 •

FieldSize property setting of Replication ID can be related to a Number


field with a FieldSize property setting of Replication ID.
x Both tables belong to the same Microsoft Access database. If the
tables are linked tables, they must be tables in Microsoft Access format,
and you must open the database in which they are stored to set
referential integrity. Referential integrity can't be enforced for linked
tables from databases in other formats.
If you want Microsoft Access to enforce these rules for a relationship, select
the Enforce Referential Integrity check box when you create the
relationship. If referential integrity is enforced and you break one of the
rules with related tables, Microsoft Access displays a message and doesn't
allow the change.

36 • © Computer Society of Zimbabwe ICDL Training Materials •


• Database – Module 5 •

USE OF FORMS
It was mentioned earlier that data can be viewed in two ways, namely form
view and datasheet view. In this section you will learn how to create, modify
and use a form.

ADVANTAGES OF USING FORMS INCLUDE:


It allows data such as Object Linking and Embedding (OLE) objects to be
viewed.
It makes it easy for data to be entered from paper based forms,
Makes it easy for individual records to be displayed in the most readable
format.
Navigation buttons used with forms

Creating a Form
Microsoft Access provides tools to easily create forms.
To quickly create a form, use the AutoForm Tool. The tool will create a
form showing all the fields from the table in use, in the sequence in which
they would appear in the datasheet.

STEPS TO FOLLOW WHEN YOU WANT TO CREATE A FORM


USING THE AUTOFORM

1. Click on the Table tab in the database window


2. Click on the name of the table whose data you want to display in the
form
3. Click on the AutoForm button on the toolbar
The Microsoft Access program will create a new form containing
all the fields in the selected table. Also remember that as at this
time the form design is not saved, you need then to save it.
A form created by AutoForm displays the fields arranged in a column
down the length of the form, however this can be changed to suit your
specific needs.

• © Computer Society of Zimbabwe ICDL Training Materials • 37


• Database – Module 5 •

SAVING A FORM
1. Click on File
2. Click on Save
The Save As dialogue box
appears displaying the name
of the table you created a
form for
3. Type a name for the form
4. Click on the OK button

Exercise: Creating a Form


1. Open the Studentdata database if it is not already open
2. Click on the Tables tab
3. Click on the Student Information table
4. Click on the AutoForm button on the toolbar
To save the file follow these steps:
1. Click on the Save button
2. Type in "Enter Student Information" (as the name of the
form)
3. Click on the OK button
At this stage the form is saved. You can check if it exists by
closing the form and clicking on the Forms tab to ensure
that there is a form called Enter Student Information.

Exercise: Opening and Navigating a Form


1. Click the Forms tab in the Database window
2. Click on Enter Student Information
3. Click on the Open button
4. Click on any field name in the First record button, then
keep on pressing the Page Down key whilst observing any
changes. (If you look at the bottom of the screen the record
numbers will be moving form record 1 to record 2 then 3,
etc)

38 • © Computer Society of Zimbabwe ICDL Training Materials •


• Database – Module 5 •

5. Press Page up a few times to go to previous records


6. Click on the First Record button
You return to record 1
7. Click on the Last Record button
You are taken to the last record in the form
8. Click on the Previous Record button thrice
You are taken three records back from the last
9. Click on the Next Record Button to be taken to the next
record in the form
10. Close the form when finished
11. Close the Database
12. Close the Microsoft Access Program

Entering Data into a Database Using a Form


When a form is created using a wizard, it creates a link between the form
and the table and when you enter data using the form, the data is
automatically stored in the corresponding table.
1. Open the database and click on the Forms tab
2. Click on the desired form and click on the Open button
3. Click on the New Record navigating button
4. Start entering the data accordingly

Exercise: Adding Data into the Table Using the Form


1. Open the Enter Student Information Form
2. Click on the New Record navigating button
3. Enter the following data :
0005, Billiard Phiri, 13/06/79, Marondera in the fields
Student FileNo, Name, Surname, Date of Birth and Town
respectively
4. Press the Enter key and enter the following data as in step 3:
0006, James Phiri, 27/02/86, Gweru
5. Close the Form

• © Computer Society of Zimbabwe ICDL Training Materials • 39


• Database – Module 5 •

After doing the previous exercise your datasheet should now look like the
one below

Modify Form Layout


A form created using the AutoForm tool can be modified in different ways
such as changing the font, font size, bold, italics, underline, etc to give a
good presentation of the form. You can also change the background colour
of the form and apply shadow styles. These and other changes are done
whilst in the design view. In the design view the form does not display the
data stored in the table.

OPENING A FORM IN DESIGN VIEW


1. Click on the Forms tab in the database window
2. Click on the desired form and click on the Design button
A diagram similar to the one below appears

40 • © Computer Society of Zimbabwe ICDL Training Materials •


• Database – Module 5 •

FORM VIEWS
There are three views associated with an open form. These are Design
View, Form View and Datasheet View. To switch from one view to another,
click on the View menu or click on the View button on the toolbar.

Exercise: Modifying a Form


1. Open the form in Design View
2. Click on the Student File No field and change the font to
Comic Sans Ms and the font size to 10
Click on the Bold button
3. Right click on the Student File No field
4. Point to Special effect and click on Special Effect-
Shadowed (to put a shadow)
5. Right-click in the Field name and point to Fill/Back colour,
then click on the White colour
6. Repeat Steps 2, 3, 4 and 5 for all the Fields
7. Right click on any blank space on the form and point to
Fill/back Colour
8. Click on the pink colour
9. The background changes to Pink

• © Computer Society of Zimbabwe ICDL Training Materials • 41


• Database – Module 5 •

Arrangements of Objects in Form Layout


As you make these changes the field names are distorted and they may
not fit into the text box. You then need to resize and move the text boxes by
dragging.

TO MOVE THE FIELDS


1. Point to the edges of the text box until the mouse pointer changes
from the normal select to the hand-like pointer
2. Drag the text box to the appropriate position and release the button
3. Do this for all the fields to position them nicely in line

TO RESIZE THE TEXTBOXES


1. Point to the place holders and drag
2. Release the button when you get to the proper size, i.e. when the entire
field can be displayed properly.
After this exercise your form should look like the one below.

CHANGING THE ARRANGEMENT OF OBJECTS IN A FORM LAYOUT


In this section you will learn how to rearrange the fields. As you have
discovered when a form is created using AutoForm the fields are displayed
in a column. These columns can be rearranged to meet the needs of the
designer. The most important skill is using the drag mode.
The following exercise will help you change how fields are displayed in this
form.

42 • © Computer Society of Zimbabwe ICDL Training Materials •


• Database – Module 5 •

You will arrange the fields in such a way that, the Student File No field will
be at the top middle position and the Name and Surname fields side by
side just below the Student File No Field and finally below the Name and
Surname fields there should be the Date of Birth and Town fields side by
side in the same row as shown below

Importing an Image or Graphic File into a Form


Microsoft Access allows you to add objects created or available from other
applications to a Microsoft Access form or report. When you add a picture
or object you have to choose between it being bound or unbound. A bound
object is stored in a table. When you move to a new record, the object
displayed in the form or report changes. For example, you might want to
store a picture for one of the students. An unbound object, on the other
hand, is stored in the design of the form or report. When you move to a
new record, the object doesn't change. This can be useful in situations
where you want to add a logo to a form or report. In addition to these two
options available from the toolbox toolbar, you can add an image using
image control since it loads much faster than unbound object frames.
Another important consideration when adding images is the SizeMode
property box, available when you right-click on the image, select Properties
and then the All tab.
x Clip displays the picture at actual size. If the picture is larger than the
area within the control, the image is cut off.
x Stretch sizes the picture to fit the area within the control. This setting
may distort the image.
x Zoom displays the picture in its entirety after sizing it to fill either the
height or width of the area within the control. This setting won't distort
the image.

• © Computer Society of Zimbabwe ICDL Training Materials • 43


• Database – Module 5 •

The form or report has to be opened in Design view for you to


add images to it.

Exercise: Importing Images into a Form


1. Open the Enter Student Information form in Design View
2. Click the Toolbox button ( ) if the toolbox is not visible
on your screen
3. Click the Image control button
4. Drag the mouse to create a small box for the image just
below the form
Notice that the form window increases its window to
accommodate the image
5. Use the Look in drop-down arrow to select the location
where the image file is located and then click on the image
and press the OK
In this case we selected the Agree image from the Popular
folder which is a sub-menu of Clipart which belongs to the
Microsoft Office folder
6. Due to the SizeMode feature being active, the picture may
appear cut-off as happened in this case
7. Right-click on the image and select Properties
8. Click the SizeMode drop-down arrow and select Zoom
9. Click the Close button of the image
window 9
Notice that the full image is now reduced
to the size you selected
10. Press the Delete key (to remove the image)
11. Click on Insert and select
Object…
12. Scroll down the Object
Type: list box until you
select Microsoft Clip 12
Gallery

44 • © Computer Society of Zimbabwe ICDL Training Materials •


• Database – Module 5 •

13. Click the OK button


14. Open the Academic Category and insert one of the clips
Notice that the clip fills the whole form window
15. Repeat steps 7 to 9 to change the SizeMode to Zoom
16. Go to one of the edges of the image and reduce its size
17. Position the image in the top right corner of the form
18. Right-click the image and select Properties. Click the Print
Preview button to see how the form will look like when
printed
19. From the All tab or the Format tab, change the Back Style
to Transparent. Click the Print Preview button to see how
the form will look like when printed. Your form should look
similar to the one below

• © Computer Society of Zimbabwe ICDL Training Materials • 45


• Database – Module 5 •

RETRIEVE INFORMATION

WHAT IS A QUERY?
A query is the most important tool for turning the data in a database into
information. A query must be based on the table. Queries are mainly used
to search for several fields based on certain criteria, for example in the
database you have been creating you can decide to look for all those students
who live in Gweru and only students from this town should be displayed.

Basic Operations
With a query you can
x Search on several fields
x Specify several conditions(known as criteria) on one field
x Sort the results in the order of your choice
x Save the design of the query so that it can be run regularly
x Perform calculations on the data
x Also base forms and reports on stored queries

The Query Form

46 • © Computer Society of Zimbabwe ICDL Training Materials •


• Database – Module 5 •

Create a Simple Query


1. Click on the Queries tab in the Database window
2. Click on the New button
3. Click on the View button on the tool bar to go to the Design
View
4. Click on the desired table
5. Click on the Add button then on the Close button
6. Complete the query form as desired
7. Click on the Run button on the Toolbar to display the search
8. Click on the Query Design from the Query View button to return to
the query form
9. Click on the Save button on the toolbar and type the name of
the Query, and then on the OK button
In the exercise that follows you will create a query that will search for the
students who stay in Gweru.

Exercise: Create a Query


1. Open the Studentdata database
2. Click on the Queries tab, and click on the New button
3. Click on the Student information table
4. Click on the Add button
5. Click on the Close button of the Show Table dialog box to
close it
6. Click in the first field cell and select the Town field from the
list box
7. Click in the Criteria cell and type Gweru
8. Click in the next field cell and select the Name field and
click in the check box in the Show cell
9. Click in the third field cell and select the Surname field.
Click in the check box in the Show cell
10. Click on the Run button on the toolbar to run the query

• © Computer Society of Zimbabwe ICDL Training Materials • 47


• Database – Module 5 •

11. Click on the View button on the tool bar to go to the Design
View
12. Click on the Save button on the toolbar and type Students
from Gweru
13. Click on OK
14. Close the Query Design form
12

The diagram below shows the result of this query

CREATING QUERIES WITH MULTIPLE CRITERIA


There are two types of multiple criteria:
1. Those that contain values that match both criteria (these use the And
condition)
2. Those that contain values that match either of the criteria (these use
the Or condition)

48 • © Computer Society of Zimbabwe ICDL Training Materials •


• Database – Module 5 •

If you want to see the values that match both criteria, type the criteria on a
single row (in each individual field) in the QBE (Query By Example) grid. If
you type criteria in a wrong field, no results will be available. If you type
criteria in a blank field you will receive the error message shown below.

Exercise: Multiple Query Based on And Condition


1. Open the Studentdata database
2. Click on the Queries tab and then click on the New button
3. In the New Query dialog box, select Design view and then
click the OK button
4. Click on the Student Information table
5. Click on the Add button
6. Click on the Close button of the Show table dialog box to
close it
7. Click in the Field row list box and select the Name field
Notice that the Show row for the field is automatically
selected, meaning that the field will be visible in the query
to be created
8. Click in the next Field row list box and select the Surname
field

9. Click in the next Field row list box and select the Town
10. In the Criteria row type Banda in the Surname column
Notice that Microsoft Access encloses text in apostrophe
marks
11. In the Criteria row type Gweru in the Town column
The other Banda will not appear as their town is not Gweru.
The criteria looks for all records with Banda as a surname
as well as (and) resident in a town called Gweru

• © Computer Society of Zimbabwe ICDL Training Materials • 49


• Database – Module 5 •

12. Click the Run button

13. Click on the Save button on the toolbar and type And
condition as the name of the query in the Query Name
text box
14. Click on the OK button
15. Close the Select Query dialog box

If you want to see the values that match either of the criteria (Or condition),
type the criteria on different criteria rows in the QBE.
Make sure that you type the criteria in the correct field, for example ensuring
that you type Gweru in the Town field and not in any other criteria row.
As an example we will use the Studentdata database to find the people
who either live in Gweru or have Banda as a surname

Exercise: Multiple Query Based on Or Condition


1. Open the Studentdata database
2. Click on the Queries tab, and click on the New button
3. In the New Query dialog box, select Design view and click
the OK button
4. Click on the Student information table
5. Click on the Add button
6. Click on the Close button of the Show Table dialog box to
close it
7. Click in the Field row list box and select the Name field
Notice that the Show row for the field is automatically
selected, meaning that the field will be visible in the query
to be created
8. Click in the next Field row list box and select the Surname
field

50 • © Computer Society of Zimbabwe ICDL Training Materials •


• Database – Module 5 •

9. Click in the next Field row list box and select the Town
10. In the Criteria row type Banda in the Surname column
Notice that Microsoft Access encloses text in apostrophe
marks
11. In the Or Criteria row type Gweru in the Town column
12. Click the Run button
13. Click on the Save button on the toolbar and type Or
condition as the name of the query in the Query Name
text box
14. Click on the OK button
15. Close the Select Query dialog box
16. Open the query and go to design view. Find out what is
wrong about typing Gweru in the or criteria row of the
surname column.

Exercise: Criteria Based on Dates


1. Open the Student information query and go to design view
2. Move to the Date of Birth column. Press Shift+F2 so as to
enlarge the criteria row
3. Type Between [Enter beginning date:] And [Enter ending
date:]. Press Enter or click the OK button to return to the
criteria row
4. Click the Run button
5. On the Enter beginning date prompt type 01/01/70

6. On the Enter ending date prompt type 31/12/74


The 2 people born during this period are displayed

• © Computer Society of Zimbabwe ICDL Training Materials • 51


• Database – Module 5 •

Adding Filters
Filters are used to display records or sort records using form view or
datasheet view. You may have used these in Ms-Excel when doing ICDL
Module 4 Spreadsheets.

SIMILARITIES BETWEEN A FILTER AND A QUERY


x Filters are easily applied while using the form or datasheet view
x A filter can quickly sort records while data is being viewed or edited
x A filter reduces the group of records to be displayed when editing
x It is also easy to apply and remove a filter
x Filters CANNOT be used to create reports

HOW TO ADD FILTERS


1. Open the table in datasheet view
2. Click the Filter By Form button
The Filter By Form window appears
3. Click on the arrow for the required field name
4. Select the required data from the drop down menu
5. Click on the Apply Filter button
The filter is applied and the dynaset appears
6. View the records and click the Remove Filter button when
finished
7. Close the table

52 • © Computer Society of Zimbabwe ICDL Training Materials •


• Database – Module 5 •

Exercise: Adding Filters


1. Open the Student Information table in datasheet view
2. Click the Filter By Form button
3. The Filter By Form window
3
appears
4. Click on the arrow for the
Town field name
5. Select Gweru from the drop
down menu
6. Click on the Apply Filter 4
button
7. The filter is applied and the
dynaset appears
8. View the records
9. Click the Remove Filter button when finished
10. Close the table
The diagram below shows the resulting two filtered records

Refine a Query

ADDING FIELDS TO A QUERY


You can add fields to a query so that they may be displayed when the
query is run. To accomplish this, you have to make sure that the check
boxes in the show cells are checked.
To add a field to the query form simply drag the desired field name from
the table field list to the desired field cell or select the field from the field cell
list box.
To add Multiple fields, select all the desired fields and then drag them to the
desired cell.

• © Computer Society of Zimbabwe ICDL Training Materials • 53


• Database – Module 5 •

REMOVING A FIELD FROM A QUERY


1. Click the column selector above the field name to be deleted
2. Press the Delete Key

Select and Sort


The records in a dynaset can be sorted by any field, either ascending or
descending and one can even sort multiple fields.
A dynaset is the result produced by running a query or filtering.
To assign a sort to a field the following steps are used:
1. Click in the Sort cell of the field by which to sort
2. Click on the OK button
3. Select the desired Sort

MULTI-FIELD SORTING
When many fields are used in sorting, Microsoft Access processes the sort
specifications from left to right. The most important sort field is the leftmost
field and the less important sort fields are placed in order of importance to
the right of the most important sort field. This only applies if you use the
Design view screen of the query as shown below:

As an example, if you Sort Ascending for both the Surname and the
Name the results will be as follows. Access will sort the data first by
Surname (in alphabetical order) but where surnames are similar (that is
they are the same), it will sort that surname based on the alphabetical
order of the names.

Create a simple query with similar names but different surnames


and vice versa to see the event. Sort ascending and then descending.
In datasheet view use the Sort icons to see the results.

54 • © Computer Society of Zimbabwe ICDL Training Materials •


• Database – Module 5 •

If you need to sort your data using one field only, then you can make use
of the Sort icons (available from the Datasheet toolbar) shown below:
Sort Ascending icon Sort Ascending icon

USING COMMON LOGICAL OPERATORS


If you need your data to hold one of two values, then you can select the
Yes/No field. This field can accept any of the following fields:
(i) Yes or No
(ii) True or False
(iii) On or Off
Logical operators can be used in instances where you want to compare
data or see data belonging in a particular range.
The following operators are used:

Logical Meaning Example


operator
< less than <20000
<= less than or equal to <=20000
> greater than >20000
>= greater than or equal to >=20000
Between Between two values Between 15000 and 20000

Remember that the value must be written in the criteria row of the field you
want. For example if you have a field called Salary, then while in Design
view, move the cursor to the criteria row of the Salary column and type, for
example <20000. This will result in only those salaries below 20000 being
displayed.
You can also choose to sort the results in ascending or descending order
or by multiple criteria.

• © Computer Society of Zimbabwe ICDL Training Materials • 55


• Database – Module 5 •

WORKING WITH REPORTS


Reports enable you to present information in the way that you want to see it.
One important difference between reports and forms is that reports do not
allow you to alter the data.

FUNCTIONS OF REPORTS
Microsoft Access reports use the concept of "What you See Is What You
Print". Because you have control over the size and appearance of everything
on a report, you can display the information the way you want to see it.
x You can group and sort the data in the report. By choosing to group
the report on a field that contains repeating values, you can ensure
that the value is shown only once on the report
x Do calculations on the data in the report
x Show data from more than one table as long as the tables are related
x Display graphics and images

Creating and Saving Reports Based on Tables/Queries


TYPES OF REPORTS
There are different types of reports; the ones used more frequently are the
Columnar Report and the Tabular report. The following diagrams represent
information in Columnar and Tabular reports.

56 • © Computer Society of Zimbabwe ICDL Training Materials •


• Database – Module 5 •

CREATING A REPORT
Creating a Report from scratch is laborious and tiresome. In Microsoft Access
it is easy and fast to create reports by using the Wizards. It is recommended
that you use some of the following Wizards for simple reports, Auto Report
Columnar, Auto Report Tabular, Report wizard or Label Wizard.

Exercise: Creating a Report Using the Report Wizard


The wizard asks you detailed questions about the record sources,
fields, layout, and format you want and creates a report based
on your answers.
1. Click the Report tab from the Objects tab while in the
Database Window
To open the Database window from any other window,
click on the Database icon or press the F11 key from
the keyboard
2. Select the option Create
report by using wizard
3. Select Student Information
(or any other database you
may have created) from the
Table/Queries drop-down list
4. The Available fields section
gives you a chance to select
the fields you want to
include in the report
In our case we used the button, which selects all the
fields to be part of the report
5. Click the Next button
(We will look at grouping in a
later section)
6. Select to sort the records by
Surname.
For the next field to sort by
select Name.
Notice that if you want to sort
in descending order, you just click on the Ascending
button to toggle between the two sort options.

• © Computer Society of Zimbabwe ICDL Training Materials • 57


• Database – Module 5 •

7. Click on Next. This box allows us


to choose the layout of the report.
8. Select each of the layout options
in turn to see how they make the
preview appear
Select Justified as the Layout
option and then click the Next
button
9. This screen allows you to choose from one of the Access in-
built styles. Choose one of your choice after having clicked
each in turn to see how they look.
Click the Next button
10. The next screen asks you to give the report a suitable name
(it gives the name of the table or query you based it on).
Do not change this name in this case.
Select the Preview the report option if it is not already
selected.
This screen also gives you the option to modify the report's
design
11. Click the Finish button

Grouping Data and Using Report Totals


Some of the queries you create may be based on more than one table
where you would have used a one-to-many relationship. This results in the
same data being repeated.
By grouping the report on a field that contains repeating values, the value
will be shown only once in the report.
The other advantage is that the records containing that data will be grouped
together.
With this version of Access, the easiest way to create groups and use totals
and sub-totals is through the Report wizard.
Create a simple table with the following details. You are free to add more
records.

58 • © Computer Society of Zimbabwe ICDL Training Materials •


• Database – Module 5 •

Surname Forename Department Salary


Mpatsi George Administration $18500,00
Taruvinga Wilfred Administration $18500,00
Chogumaira Debrah Secretarial $18000,00
Guvheya Listen Secretarial $18200,00
Machona Emerly Secretarial $18400,00
Timire Ronald Accounts $24300,00
Mupfumira Andrew Accounts $18485,00
Zhanero Kumbidzi Accounts $19200,00
Gubunje Maxwell Accounts $22400,00
Ruka Abel Accounts $21900,00

Save the table with the name Employees.


Select the Surname to be the primary key when the computer prompts
you for one.

Exercise: Using Groups and Totals in Reports


1. Click the Report tab from the Objects tab
2. Select the option Create report by using wizard
3. Select Employees from the Choose the table or query where
the object's data comes from: drop-down list if it is not
already selected
4. Click the button under the Available Fields section as
we want all the fields to be part of the report
5. Click the Next button
6. In the Do you want to add any grouping levels? section,
select Department from the possible Grouping levels and
then click the button to choose it.
Notice that if we want to group using more than one
criteria we would continue selecting grouping level fields
and then use the priority buttons to choose the most
important grouping levels first.

• © Computer Society of Zimbabwe ICDL Training Materials • 59


• Database – Module 5 •

7. Click the button near the bottom-left of


the screen. Click the Next button.
8. Select to sort the data by Surname and then Forename
9. Click the button
10. Click in the Sum check
box so as to calculate
totals for the Salary field.
Selecting the Summary
Only option button will
result in only the totals
and the summary of the
number of records being
displayed. The individual
records will not be
displayed.
11. Click the OK button and then click the Next button
12. In the next screen select the Block option button as the
layout style. Click the Next button
13. Select a style of your own in the next screen. Click the Next
button
14. Do not worry about giving the report a new name. Click
the Finish button.
A preview of the report appears. Do not close the report as
we will have another exercise in the next section on
modifying reports.

The report shows the employees in a department grouped together in


ascending order of surnames. The subtotal of the numeric field, Salary is
shown for each group. The grand total of salaries for all departments is
shown at the bottom (as the report footer).

60 • © Computer Society of Zimbabwe ICDL Training Materials •


• Database – Module 5 •

GROUPING USING DESIGN VIEW


Open the Employee report in design view

Click the Sorting and Grouping button


If this report had another suitable field to group on, you would click on the
field and then set the Group Header or Footer to Yes. Try it with the Surname
field so that you can be able to see how to group on another field.

Modifying a Report
There are so many things that can be modified on a report. We will look at
some of these things.
The appearance of the whole report can be changed by clicking on the
Autoformat button . Select the AutoFormat that you want.
If when you created the Employee table you did not change the default text
size (50), you will notice that for example the figures do not all come out.
We need to enlarge the fields for the salary fields as well as the grand total
fields.
Just as with Microsoft Word, you can format the appearance of the text in
any way you like. We have done most of this when we were looking at the
section on Forms. The procedures are also the same for reports. All you
need to do is to select the label controls of the text and then applying the
appropriate formats from the formatting toolbar.
The data in the detail section can also be changed so that it appears
differently. All you need to do is to select the control and then right-click (or
click on the Properties button). Set the format properties you want.

• © Computer Society of Zimbabwe ICDL Training Materials • 61


• Database – Module 5 •

As an exercise, open the Employees report in design view and change the
salary data so that it does not have any decimal places. (Hint: Select the
Salary control from the detail section, right-click and select Properties. From
the Format tab, look for the decimal places row and change it to 0. Close
the dialog box and preview the report to see the effect.). Change a number
of formats so that you can be used to changing formats.
Should you want to include new labels in your report, click the Label button
. This button is available after you have clicked the Toolbox button
. Drag an area in the report where you want the label to appear and
then type in the text for the label. Press the Enter key or click out side the
control.
To edit the text in a label, select the text and type in the new text.

Exercise: Modifying a Report


1. Click the Close button of the preview window
The report will appear in design view
2. The sum totals that where not appearing fully in the report
are available from the Department footer section. Click on
the sum field. Drag it to the left so as to increase its size
3. Repeat the same procedure for the sum field in the Report
footer section
4. Click on the Preview button
Your figures should all be visible now
5. You might also not be interested in your report having the
phrase after each department which says, Summary for
department = 'Accounts' (5 detail records)
To remove the phrase, click the Design view button.
6. Click on the
portion of the Department footer section. Press the Delete
key
7. Click the Preview button
The phrase should be no longer visible in your report
8. Click the Design view button

62 • © Computer Society of Zimbabwe ICDL Training Materials •


• Database – Module 5 •

9. In the Detail section, click on Department. Press the Shift


key and without letting go of it, click on Surname, Forename
and Salary in turn (shift-click concept)
This will result in all of them being selected
10. Apply bold, italics and change the font colour to Blue
11. Click the Preview button to see the report
12. To save this file, click the File menu and select Save As/
Export… Type in Employees modified as the name of the
file in the dialog box that appears.

Creating Headers and Footers


The diagram below shows the Design view of the Employee modified report

• © Computer Society of Zimbabwe ICDL Training Materials • 63


• Database – Module 5 •

There are a number of different types of report headers and footers:


x Report header: The detail in this section will appear only once at the
top of the first page of the report
x Report footer: The detail in this section will appear only once at the
bottom of the last page of the report
x Page header: The detail in this section will appear at the top of every
page of the report
x Page footer: The detail in this section will appear at the bottom of
every page of the report
x Grouping field headers: You can group a report on up to 10 fields
with the first one being most significant in that order
x Grouping field footers: You can group a report on up to 10 fields
with the first one being most significant in that order
x Page header: The detail in this section will appear at the top of each
page of the report
x Page footer: The detail in this section will appear at the bottom of
each page of the report
Please note that with Access, you can only add headers and footers as a
pair.
To add a header and footer:
1. Open the report in Design view
2. Click on the View menu
3. Select either (or both) of Page Header/
Footer or Report Header/Footer
4. The appropriate section will be added to your
report design.
5. Click on the section to make sure it is selected.
6. You can then use the label button to include
detail for the section. You can also use the
Insert menu to include the date, time or page
numbers in the section. Take time to go to
each of these menu options and see the
various options you have of the date, time or
page number formats to choose from.

64 • © Computer Society of Zimbabwe ICDL Training Materials •


• Database – Module 5 •

Customizing Headers and Footers


There can be instances when you just want your report to have just the
header and not the footer or vice versa. This can be achieved by the following
procedure which will be done as an exercise:

Exercise: Customising Headers and Footers


1. Open the Employees report in Design view
2. Click on the View menu
3. Select Report Header/Footer
4. Click the Yes button of
the prompt that appears
to acknowledge that
you know longer want
the Report header and
footer as part of your
report
5. Close the file. DO NOT
save changes
6. Repeat steps 1 to 2
7. Click on the Report Footer section to select it
8. Click the Properties button (or right-click on the section
and then select Properties)
9. Click on the All tab if it is not already selected.
10. Click on the Visible row and change it to No. Close the
dialog box.
11. Click the Preview button. The Report footer should no longer
be visible.
OR more simply, instead of steps 7 to 11, select the controls
in the report footer section and then press the Delete key.
Try it.

• © Computer Society of Zimbabwe ICDL Training Materials • 65


• Database – Module 5 •

Deleting a Report
1. Make sure that the report you wish to delete is closed.
If this is not done, you will get an error message similar to the one
below

2. Click on the Database icon or press the F11 key from the
keyboard to open the Database window if you are not in it.
3. Click the Reports tab to see all the reports available for the database.
4. Click on the name of the report you wish to delete.
Press the Delete key from the keyboard or click on the Delete
icon from the Database window toolbar.

66 • © Computer Society of Zimbabwe ICDL Training Materials •


• Database – Module 5 •

PREPARING OUTPUTS
Set page setup options for a table, query, form, or report
1. On the File menu, click Page Setup.
2. Click the following tabs for the options you want to set:

x Margins. To set margins and whether to print data only (for


forms and reports) or to print headings (for tables or queries).

x Page. To set orientation, paper size, and printer.

x Columns. To set number, size, and layout of columns (for


forms and reports).
3. Click OK.
Microsoft Access stores the settings for page setup options with a
form or report, so you set these options only once for each form or
report. For tables, queries, and modules, you must set page setup
options every time you print.

PRINTING A REPORT
Before you print a report for the first time, you might want to check the
margins, page orientation, and other page setup options. For more
information, click .
1. On the File menu, click Print.
2. Enter the settings you want in the Print dialog box.

x Under Printer, specify a printer.

x Under Print Range, specify all pages or a range of pages.

x Under Copies, specify the number of copies and whether


they should be collated.
3. Click OK.

• © Computer Society of Zimbabwe ICDL Training Materials • 67

Potrebbero piacerti anche