Professional Documents
Culture Documents
Iaa MS Access 2003 PDF
Iaa MS Access 2003 PDF
Introduction
The aim of this document is to introduce basic techniques for creating a simple database
using the Microsoft Access 2003 relational database management system (RDBMS).
You will undertake a case study to build a simple database consisting of tables,
relationships, forms and reports and queries. This will demonstrate the need to work out
your requirements before attempting to design a database.
You will use some of the Wizards that are provided with Microsoft Access 2003.
As we work we will introduce terminology commonly used in database design and in the
Windows 2000 environment
Prerequisites
No prior database or development experience is assumed, however Windows experience
is essential. You should be familiar with;
Keyboard layout
Use of mouse
Selecting items from menus
Using toolbars
Using dialogue boxes
Using On-line Help for Windows
Acknowledgements
These workshop notes are based on the Teachers Notes and Exercises supplied by
Software Made Simple Guide to Microsoft Office 2000. Copies of the Guide are
available to students and staff of Birkbeck either in paper form from ITS Help Desk,
MB 151 or from the College Intranet at
http://www.bbk.ac.uk/its/help/documentation/. Help Desk is open on weekdays
10.00am - 8.00pm in term time, and 10.00am - 6.00pm in vacations. References to
the SMS guides are indicated in brackets, e.g. (SMS 2.10)
Contents
1 Introduction 1
2 Some Theory 1
2.1 What is a Database? 1
2.2 Where does Microsoft Access 2003 fit in? 2
2.3 Steps in Designing and Building a Database 2
3 Case Study 2
3.1 About the Educational Institutions 3
3.2 About the orders 3
3.3 Analysis 3
Doc 5.131 Ver 2 Introduction to Access 2003
1 Introduction
The aims of this training material are:
To introduce basic techniques for creating a database using the
Microsoft Access 2003 relational database management system (RDBMS).
In this introductory material we will not cover the more advanced features of
Microsoft Access 2003 such as macros and modules. These topics are necessary
for the development of full-blown applications
To demonstrate the need for requirements analysis before attempting
a database design. Before you create a document with a word-processor, you
need to do some planning of the content and appearance. For a simple
document you may begin typing straight away. However, a database needs much
more planning before you even think of using a RDBMS such as Microsoft Access
2003
To build a simple database. You will start by learning about the topics
needed to build a single table database, that is the simplest type of database, such
as a list of names and addresses. Topics include what is a database, steps in
designing and building a database, Tables, Forms and Reports and Queries
To become familiar with using some of Wizards that are provided with
Microsoft Access 2003
To introduce terminology commonly used in database design and in
the Windows 2000 environment. In order to understand the on-line help and
other further reading, you need to become familiar with the terminology that is
used in the documents
Work through these notes in sequence. Read the hints and explanations before you
attempt the exercises. The exercises need to be completed in the order that they
appear, as they depend on objects 1 that have been created in previous exercise.
2 Some Theory
Depending on the way data is modelled, we have relational, network, hierarchical, and
object-oriented data models. The data model defines how real-world data is
represented in the database. DBMSs are typically tied to one type of data model.
1
Database components in Access 2003 are referred to as objects.
1
Doc. 5.131 Introduction to Access 2003
Microsoft Access 2003 is based on the relational model and is therefore a relational
DBMS, or RDBMS.
Relational databases are built up of Tables. The column headers in the table are
called fields. The rows of data in the table are called records. RDBMSs are extremely
fussy and insist that each record is uniquely identified by one or more fields. We will
see when we design tables how a unique identifier or key is used.
To illustrate what this means, we will examine a sample case study, and then build a
very simple database to provide the required functions.
3 Case Study
The database that you are going to build is to hold the records of the Software
Made Simple company. The company sells training material to educational
2
Introduction to Access 2003 Doc. 5.131
institutions. They need to keep details of the Institutions that they deal with and the
orders that they place.
The institution code. This links each order to the institution that placed it
The order number. This uniquely identifies the order
If the order is for books then they need to know the number. Since all the
books are the same price there is no need at this stage to break down the order
into book titles
The value of the order
The order type i.e. whether it is for books or CD-ROM
CD Renewal date. Sites buy an annual licence to make copies of the material on
the CD-ROM so SMS need to know the renewal date
3.3 Analysis
The important thing at this stage is not your knowledge of computers, but an
understanding of the problem. As this is not a course in Systems Analysis, the
analysis has been done for you, so that you can practise using Microsoft Access 2003
straight away. The Entities about which to keep information are Institutions and
Orders, so we will start with two tables in our database.
Since the institution is represented by the site contact, the table representing the
institution will be called Contacts. We will call our other table Orders. Tables are
structured into fields (columns) and records (rows). All records must have the same
fields, though as we shall see in this example there may be instances where a field is
redundant in some records but not in others.
The Attributes (i.e. the details that we need to know) of a Contact are the
institution code, the number of students, the name of the institution, the
educational sector and the contacts forename and surname. Since the contact is
representing an institution the institution code must be unique
The attributes of an Order are the order number, which must be unique, the
institution code, the value of the order and the order type (CD-ROM or books).
For book orders we need the number of books and for CD-ROM orders we
3
Doc. 5.131 Introduction to Access 2003
need the licence renewal date. For CD-ROM orders the number of books field
is redundant. For book orders the renewal date is redundant. However, we
must include the field for all records to maintain a consistent structure
In order to identify the Relationship between an institution (represented in the
database by its Contact) and its orders we will give each institution a unique
identifier in the Contacts table. We will include this identifier as a field in the
Orders table. It is good practice, when designing a database, to use unique
identifiers. In our example each contact is uniquely identified by the institution
code. There are good reasons for this. The contact might change in the future.
In order to link an institution to the orders it has placed we need to maintain
consistency. Even if the contact name changes the institution code remains the
same so we still know where to send the order. In addition, there may be
several institutions with contacts named (say) John Smith
)The field that uniquely identifies a record in a database is called the Primary Key
4
Introduction to Access 2003 Doc. 5.131
4 Creating a database
Microsoft Access 2003 also provides wizards. Wizards are software tools that help you
with a programmes features. However, in this document you will learn how to
create your database from scratch, so that you are better able to match the database
to the requirement. SMS guide 2.4 describes how to create a database using a
wizard.
At the Windows log in prompt, type your username in the Username box. Press
the TAB key to move to the Password box, and type your password. Then press
the ENTER key or click on OK Wait a few minutes while Windows 2000 checks
your username and password, and allocates your network resources
Click on the Start button on the taskbar at the bottom of the screen. The Start
Menu will appear
Click on Programs on the Start Menu
Click on Microsoft Office on the Program menu and then on Microsoft
Access 2003
You have now created a file that will become the database. Unlike programs such as
Word and Excel, Access saves the objects that you create and the data that you enter
automatically to this file.
5
Doc. 5.131 Introduction to Access 2003
When you create a new database it will look something like Figure 4-1.
On the left of the window are buttons representing various database objects.
Select the class of object that you wish to work on by clicking on the button.
Tables are the foundation of the database; just as you start building a house by
laying the foundations you start building a database by creating the tables. The
first time that you use the database the table button is selected by default
On the right of the window you will see a list of tasks that you can perform on
the selected class of object. If a wizard matches your requirements, then it is the
simplest way to create a table (see SMS section 2.7). In this document we will
learn how to create a table from scratch
6
Introduction to Access 2003 Doc. 5.131
Choose Save As from the File menu and save your table as Contacts
When Microsoft Access 2003 asks if you want to create a primary key now click
on Yes
7
Doc. 5.131 Introduction to Access 2003
Note that you do not have to save the data. Microsoft Access 2003 saves each record
automatically as you enter it
8
Introduction to Access 2003 Doc. 5.131
9
Doc. 5.131 Introduction to Access 2003
10
Introduction to Access 2003 Doc. 5.131
Sort the table in ascending order on the Value field. What is the fourth value?
6 Queries
The next task is to create a query that finds all the records in the Contacts table.
We will then see how to apply criteria to the query to return dynasets.
In the above example you moved all the available fields from one table. However, if
you only need some fields
11
Doc. 5.131 Introduction to Access 2003
If you need fields from another table or query select the other table or query
from the Table/Query list
If you change your mind about a selected field, select it in the Selected fields list
and click on < to return it to the Available fields list.
Query by Example
(QBE) grid
Run the query by clicking on the Run button on the toolbar at the top of the
screen (see right)
Close your query by clicking on the close button (x) at the top right corner of
the query window. (When asked if you want to save changes click on No.)
12
Introduction to Access 2003 Doc. 5.131
Run the query. The results should look like Figure 6-3
13
Doc. 5.131 Introduction to Access 2003
) If you do not want to display a field then clear the check box in the Show row in
the designer view.
) The records are sorted in ascending order by Institution code. In design view you can
choose to sort on a different field by clicking in the Sort row of the column for your
chosen field. You can select a sort order from the drop down menu.
14
Introduction to Access 2003 Doc. 5.131
Hint: In the following exercises include only those fields that are essential. For
example, in the next exercise you are interested only in those fields that define the
order type as books and the number of books purchased. You need to display the
totals row to locate the maximum function.
7 Forms
15
Doc. 5.131 Introduction to Access 2003
Each form is based on either a table or a query. In order to create a form that uses
fields from more than one table you will need to create a query that contains all the
necessary fields. The quickest way to create a form is by using the form wizard.
16
Introduction to Access 2003 Doc. 5.131
To change a property click in the relevant field. Some properties will display a
drop down arrow, allowing you to choose a value from a menu. For other
properties you will need to type a value.
) To select several objects located next to each other, hold down the SHIFT key and
click on each object in turn.
) To select several objects that are not next to each other hold down the CTRL key and
click on each object in turn
) You may have used a similar technique when selecting files with Windows Explorer.
Windows applications use consistent techniques for performing tasks. The
techniques explained above work equally well for selecting emails in Outlook and
selecting files in Windows Explorer
) All Windows applications require you to select an object before you try to do
anything with it. For example, you must select a block of text in Word before you
can copy it
Still holding down the SHIFT key display the properties window (as explained
above). The properties window should have the title Multiple Selection
If the Format tab is not on top click on it to select it
Click to select Fore Color
(scroll down the window if
you cannot see it). A
17
Doc. 5.131 Introduction to Access 2003
continuation button (), appears (see right). Click on it to see the choice of
colours
Select a suitable shade of red and click on OK
Click on the form and you will see that the text labels are now red
Select Save from the file menu to save your design
Position
cursor here
Drag the detail section down so that a gap of about 1cm appears between the
form header and detail sections.
Click on the label tool on the tool box to select it. To find the tool move the
cursor along the tool bar without clicking on the buttons. You will see a label
appear to indicate the function of the button. This is called Hover Help
Click in the space that you created between the header and detail sections, then
drag to draw a box. In the box type Software made Simple Contacts
18
Introduction to Access 2003 Doc. 5.131
In the Format section of the properties box set the Text align property to
center, font size to 10 and font weight to semi bold. Set the fore colour
to a colour of your choice
Save your changes
8 Reports
(SMS Section 6)
Reporting is the way in which you choose to present the contents of your database
as printed pages.
Reports enable you to select which fields will be printed out and what data
should be included. Reports can also summarise data in various ways
Microsoft Access 2003 gives you the opportunity to design the layout of a
particular report, including the position of headings, labels and the data itself
along with graphics such as pictures and logos
Reports can take their data from tables or existing queries or you may create a
query especially for the report
In order to create a report that uses fields from more than one table a query
should be created which contains all the necessary fields. For example you could
create a report based on the Large Institutions Query that you created, which
uses data from the contacts and orders tables
The best way to create a report is by using the report wizard
We will use the Contacts table to create a report grouping the fields by Edu
Sector. We will sort on Institution and Surname fields in ascending order, and
display the report in landscape format.
19
Doc. 5.131 Introduction to Access 2003
In the sorting window select Institution in the box labelled 1 and Surname in
the box labelled 2. The sort buttons are already set for ascending order. Click
on next >
In the layout window select Stepped layout and landscape orientation. Click
on next >
Select a style that you like and click on Next >
Type the title Contacts Report in the title box and click on Finish
Your report will now appear as a Print Preview. You can print it by either clicking on
the print button on the toolbar or by selecting print from the file menu.
You will usually need to refine some aspect of the report in order to present
information in the clearest possible way (SMS Section 6.2).
The techniques that you use for modifying the controls on a report are exactly the
same as for a form. You can click on controls to select them, and use the CTRL and
SHIFT keys to make multiple selections
20
Introduction to Access 2003 Doc. 5.131
You may wish to experiment with different styles, layouts and summary options.
SMS section 6 gives you some ideas about what you can do with Microsoft Office
2003. In the following section we will consider how you can combine components of
Microsoft Office 2003 to produce customised documents.
21
Doc. 5.131 Introduction to Access 2003
Figure 8-2
Click on the button Insert Merge Fields. You will see a list of fields from your
contacts table. Double-click on Forename (or click once and click insert). You
will see a place marker <<Forename>> in your document.
Type a space, then insert the merge field surname
Type the some text in your letter so that it appears as shown below:
Dear Forename Surname
Yours Sincerely
Simon Simple
Use Hover Help to locate the button Merge to New Document. When you
click on this button Word will generate a set of form letters, based on your Access
data source. The names of the people in the contacts table have been substituted
for the place markers in your master document. This document may be printed
9 Relationships
In the small sample data base that youve worked with you may wonder why we did
not combine all the data in one table SMS Orders (Table 5)
22
Introduction to Access 2003 Doc. 5.131
Value Number
Order Type Text
CD Renewal Date: dd/mm/yy
Consider what would happen if an institution placed many orders. Institutions that
order books sell them on to the students and re-order each academic year. For
each order the SMS Orders table would have repeated fields for all the fields
shown above in italics.
Remember also that we simplified matters by omitting contact details such as
address, phone etc. which would otherwise have been repeated and you will see
how inefficient such a design would be. For example:
We would need to re-enter the data in italics every time an institution placed an
order time consuming, and with more scope for errors
The table would occupy more disk space
Our two table structure is more flexible. For example, if the institution contact
changes we need only change it in the Contacts table once.
23
Doc. 5.131 Introduction to Access 2003
As the database wizard takes you through the steps click on next > until it is
finished
After a few minutes Microsoft Access 2003 will create a database. From the Tools
menu select relationships. You will see that the relationships are rather
complicated! Let us look in more detail at the relationship between the Events,
Attendees and Registration tables.
Consider a similar situation. Students can attend one or more Classes; Classes are
attended by one or more Students. However, you can link students to classes by a
Registration table.
Exercise 27
Create a small database with the tables necessary to register students on classes.
(Hint you may want to look at the design of the attendees, events, and
registration tables in the Event Management database)
Create the appropriate forms & enter some test data for about 5 or 6 students
and about 3 or 4 courses. One of your courses should be Database Design.
You will need to remove the input mask from the postcode and phone number
field properties because Microsoft Access 2003 uses American masks
Create a query and generate a report to list the names of all the students who
are studying database design