5-131_02_2
-
Upload
didarul-alam -
Category
Documents
-
view
217 -
download
0
Transcript of 5-131_02_2
-
7/29/2019 5-131_02_2
1/26
INTRODUCTION TO MSACCESS 2003
Introduction
The aim of this document is to introduce basic techniques for creating a simple database
using theMicrosoft Access 2003relationaldatabase management system (RDBMS).
You will undertake a case study to build a simple database consisting oftables,
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 withMicrosoft 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 toMicrosoft 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 12 Some Theory 1
2.1 What is a Database? 12.2 Where does Microsoft Access 2003 fit in? 22.3 Steps in Designing and Building a Database 2
3 Case Study 23.1 About the Educational Institutions 3
3.2 About the orders 33.3 Analysis 3
-
7/29/2019 5-131_02_2
2/26
Doc 5.131 Ver 2 Introduction to Access 2003
3.4 Data Types 44 Creating a database 55 Working with tables 7
5.1 Creating Tables 75.2 Entering Data into a table 8
5.3 Sorting Data 95.4 More Practice on working with tables 9
6 Queries 116.1 What are Queries? 116.2 Query Wizard 116.3 Adding criteria to a query 126.4 Joining tables in a query 126.5 Calculated criteria 146.6 More practice at working with queries 14
7 Forms 157.1 What are forms? 15
7.2 Create a form with Form Wizard 167.3 Entering Data with a form 167.4 Modify the form design 167.5 Create an object on a form 187.6 More practice at working with forms 19
8 Reports 198.1 Modifying a report 208.2 More practice at working with reports 218.3 Mail Merge 21
9 Relationships 22
9.1 Why use Relationships 229.2 Types of relationships 239.3 A sample database 239.4 Finding out More about Database Design 24
About this Document
Words that you type or choose are in bold type, e.g.Choose Programs fromthe Start menu
Keys that you press are shown in small capitals e.g. press ALT Press KEY1 + KEY2 means press both keys together e.g. press CTRL + Z
Press KEY1, KEY2 means press each key consecutively e.g. press A, B General guidelines on how to perform a task are indicated by bulleted lists using
the symbol. Note that these are not tasks for you to perform now. Exercisesfor you to practice as you work through the notes are labelled Exercise, e.g.
Exercise 1 Importing Database Objects. The steps that you do to complete
the exercise are marked by round bullets ().
Hints and tips are indicated by ) If you are not very familiar with usingcomputers then you should pay particular attention to the hints and tips.
ii Birkbeck College Central Computing Services
-
7/29/2019 5-131_02_2
3/26
Introduction to Access 2003 Doc. 5.131
1 Introduction
The aims of this training material are:
To introduce basic techniques for creating a database using theMicrosoft Access 2003relational database management system (RDBMS).
In this introductory material we will not cover the more advanced features ofMicrosoft 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 attemptinga 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 asMicrosoft Access
2003
To build a simple database. You will start by learning about the topicsneeded 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 ofWizardsthat are provided withMicrosoft Access 2003
To introduce terminology commonly used in database design and inthe 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 theyappear, as they depend on objects1 that have been created in previous exercise.
2 Some Theory
2.1 What is a Database?
A database is a simply structuredcollection of data, with the emphasis very much on
structured. Everyone encounters databases in their daily lives, even if they are not in
electronic form. Telephone books, diaries, and mailing order catalogues are all
instances of databases.
Computerised databases are created, stored, manipulated and maintained using
Database Management Systems (DBMS); DBMS are the programs or groups of
programs through which we gain access to databases. In the personal computer
world, DBMSs are often referred to as database packages or database applications.
Depending on the way data is modelled, we have relational, network, hierarchical, and
object-orienteddata 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 inAccess 2003are referred to asobjects.
1
-
7/29/2019 5-131_02_2
4/26
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 ofTables. 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 recordis uniquely identified by one or more fields. We willsee when we design tables how a unique identifier or keyis used.
2.2 Where does Microsoft Access 2003 fit in?
You should consider building your database withMicrosoft Access 2003 if yourdata structures can be represented by the relationalmodel. This is true of most
business applications, and the sample databases provided withMicrosoft Access
2003 demonstrate this. Microsoft Access 2003 can be used for quite large,
complex database applications. However, even if your data structures are quite
simple, and could be easily held in a card index, you may want to consider using
Microsoft Access 2003, as it works well with Word. If you frequently need to send
out mail shots thenMicrosoft Access 2003 is particularly suitable for use with the
mail merge tool in Word
There are more specialist databases available for bibliographic databases (ITSsupply Endnote in workstation rooms). Contact ITS Reception/Help Desk on
our website for information on available documentation
If the data contained in your tables is mostly numeric data, then you are probablybetter off using a spreadsheet program such as Excel. Spreadsheet programs are
specifically designed to handle numeric data
2.3 Steps in Designing and Building a Database
Define the problem Decide what real world things (entities) you need to store information about.
For example Employees, Products, Customers, Orders. Entities are represented
by tables in the database
Decide what facts (attributes) you need to know about each entity, e.g. anEmployees date of birth, salary. Attributes are represented by fields in the tables
Decide on the relationships between the entities in the database; i.e. what attributesdo they have in common. Relationships are formed in the database between
entities that have common attributes. They have common fields in the related
tables. For example, customerFred Bloggs can place an orderfor product eggs.
So the Orders table has relationships with Customers table and Products table
Decide what information you need to extract from your data. This will allowyou to design the queries
Design Forms that will allow users to enter data values for running queries orentering data
Design Reports that will print information extracted from the database
To illustrate what this means, we will examine a sample case study, and then build a
verysimple database to provide the required functions.
3 Case Study
The database that you are going to build is to hold the records of the SoftwareMade Simple company. The company sells training material to educational
2
-
7/29/2019 5-131_02_2
5/26
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.
3.1 About the Educational Institutions
The details SMS need to know about each institution are:
A unique identifier for each institution The number of students in the institution this helps to know the potential size
of the market for their products
The educational sector whether pricing is covered by special deals for certaintypes of institutions
The name, address, phone, fax, email of the institution. For simplicity we willinclude only the institution name in our sample database
The company deals only with a named contact at each institution. SMS needs toknow who this person is
3.2 About the orders
The training material is provided either as printed books or on a CD-ROM. For each
order SMS need to know
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 usingMicrosoft 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.
TheAttributes (i.e. the details that we need to know) of a Contact are theinstitution 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 Orderare 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
-
7/29/2019 5-131_02_2
6/26
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 thedatabase by its Contact) and its orders we will give each institutiona unique
identifier in the Contacts table. We will include this identifier as a field in theOrders 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
3.4 Data Types
(SMS 2.10)
Having decided what tables we need, and what fields we need in the tables we need
to decide what type of data we are going to put in each field. Is it, for example, a
number, a date, or some text. When you are building a database from scratch you
will usually make use of theMicrosoft Office 2003 autonumber to allocate a unique
identifier for each record. Note however that if you are building a database to
contain data that already exists with a unique identifier (e.g. Student number,
National Insurance number, bank account number), you should use your existing
unique number in preference to an autonumber.
)The field that uniquely identifies a record in a database is called the Primary Key
Table 1 Fields for Contacts table
Field Name Data Type
Surname Text
Forename Text
Edu Sector Text
Institution Text
Num Students Number
Institution Code Autonumber
Table 2 Fields for Orders Table
Field Name Data Type
Institution Code Number
Order Num Autonumber
Num Books Number
Value Number
Order Type Text
CD Renewal Date: dd/mm/yy
4
-
7/29/2019 5-131_02_2
7/26
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 awizard.
Exercise 1 Starting Microsoft Access 2003 on ITSworkstations
At the Windows log in prompt, type your username in the Username box. Pressthe 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 taskbarat the bottom of the screen. The StartMenu will appear
Click on Programson the Start Menu
Click on Microsoft Office on the Program menu and then on MicrosoftAccess 2003
Exercise 2 Create a new database
On the menus, choose File New
Select Blank Database from the task pane on the right-handsideof the screen In the File New Database dialogue boxmake sure that you have selected the MyDocuments folder on your N: drive, and replace db1.mdb in the Filename
box with sms contacts.
Click on Create
You have now created a file that will become the database. Unlike programs such as
Wordand Excel,Access saves the objects that you create and the data that you enter
automatically to this file.
5
-
7/29/2019 5-131_02_2
8/26
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. Thefirst 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 onthe 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
Figure 4-1 New database
6
-
7/29/2019 5-131_02_2
9/26
Introduction to Access 2003 Doc. 5.131
5 Working with tables
5.1 Creating Tables
In the analysis section we looked at the tables needed, what fields should appear in
the tables and what data types those fields should have. It is important to realisethat we are talking about the data structures in the database. We are not talking
about the data values which will ultimately be contained in the tables. For example
the field forename is a part of the contacts table datastructure. When we enter names
(Tony, Eleanor, Nurinder) we are entering data values into the table.
Exercise 3 Create a table
Select Create table in Design view and click on the New button
In the New Table window select Design View and click on OK
Enter the field names and data types that we discussed in the analysis section.(Surname, Forename, Edu Sector, Institution, Num Students, Institution Code)
By default the field type is text. Use the TAB key to move between fields
To change the data type display the data type menu. To do this:eitherclick in the data type field, then click on the drop down arrowthat
appears in the right of the
orpress the ALT+DOWN ARROW keys together
Choose the data type that you require. Your table structure should look likeFigure 5-1
Figure 5-1 Contacts Table in Design View
Choose Save As from the File menu and save your table as Contacts
WhenMicrosoft Access 2003 asks if you want to create a primary key now click
on Yes
7
-
7/29/2019 5-131_02_2
10/26
Doc. 5.131 Introduction to Access 2003
5.2 Entering Data into a table
(SMS Section 3)
Exercise 4 Entering data into a table
Click on the datasheet viewbutton (see right). It is situated at the righthand end of the tool bar. You do not need to enter the Institution
Code as it is an autonumberAccess will do it for you. Note that if you make a
mistake and delete a recordMicrosoft Access 2003 will not reuse a number; your
numbers may therefore be different to those given in the examples. You should
useyournumbers inyourdatabase.
Enter the data values shown in Table 3. You can use the TAB key to movebetween fields. Use the BACKSPACE or DELETE key to correct mistakes
Table 3 Data values for Contacts table
Surname ForenameEduSector Institution
NumStudents
InstitutionCode
Taylor Tony School Callow Grammar500 1
Blake Victor University Lermouth 120000 2
Ambrose Guy University Mawley 8000 3
Patterson Peter College North Camber 8000 4
Keenan Penny School Abdul Kameer 600 5
Wright Eleanor College Callow 1000 6
Waverley David University Newbridge 160000 7
J ames Philip School Roberts High 700 8Su Chi Hong School Southfields Tech700 9
Patel Nurinder University Westchester 150000 10
Clarke Lenny School Wyre High 800 11
Patrick Roger School Westmouth 800 12
Parkinson Helen School Schofield Tech 900 13
Mathews Karen University Waverley 9000 14
Quentin Terry College Eastman 7000 15
Walters Trudy University Aberdare 100000 16
Peabody Ruth University Bradbury City 9000 17
Young Alice University Folklands 140000 18
Lomar Shireen University Pershore 12000 19Booth Charlie College Truman 5000 20
Cazinaska Dimen College Trowbury 5000 21
Note that you do not have to save the data. Microsoft Access 2003 saves each record
automatically as you enter it
8
-
7/29/2019 5-131_02_2
11/26
Introduction to Access 2003 Doc. 5.131
5.3 Sorting Data
(SMS Section 4.0)
Each record in the contacts table is stored in the order in which it was entered. You
will often want to view it in a different order for example sorted by date or
alphabetic order.
Exercise 5 Sorting Data
Click in the Surname field to select it
Click on the Sort Ascending button (see right) to sort the records inascending alphabetic order. What is the seventh surname in the list?
5.4 More Practice on working with tables
Now practice using the techniques that you have just learnt to create another table,
enter and sort data.
Exercise 6 Create Orders Table
Make the sms contacts database window the active window (either by clickingon it or choosing it from theWindow
menu)
Using the techniques that you learnt inExercise 3 create a table called
Orders, with the field names and datatypes shown on the right
Note that the date for renewing CD licences (CD Renewal) needs to beexpressed in Short Date format. To change the format select the CD
Renewal field, click in the Format field in the Field Properties section of the
table design view window. Click on the down arrow to display the format menu
and choose the option that you want see Figure 5-2
Save the table as Orders
9
-
7/29/2019 5-131_02_2
12/26
Doc. 5.131 Introduction to Access 2003
Figure 5-2 Field Property
Exercise 7 Entering & Sorting Orders Data
Using the technique that you learnt in Exercise 4 enter the data shown in Table 4into the Orders table. As Order Num is an autonumberthere is no need to
enter it yourself
Table 4 Orders Data
InstitutionCode
OrderNum
NumBooks Value
OrderType CD Renewal
8 1 200 1,190.00 Books
14 2 540 3,213.00 Books
11 3 0 170.00 CD 31/12/01
17 4 0 720.00 CD 05/05/02
20 5 0 720.00 CD 01/08/02
16 6 0 720.00 CD 04/08/02
13 7 0 170.00 CD 01/07/02
4 8 3200 19,040.00Books
5 9 100 595.00 Books
1 10 53 315.00 Books
2 11 0 720.00 CD
9 12 0 170.00 CD 04/03/02
10 13 0 720.00 CD 05/06/02
15 14 0 720.00 CD 20/10/0212 15 20 119.00 Books
7 16 0 720.00 CD 19/11/01
3 17 340 2,023.00 Books
6 18 0 720.00 CD 25/01/02
21 19 0 720.00 CD 27/02/02
19 20 0 720.00 CD 18/12/01
18 21 44 261.00 Books
12 22 50 298.00 Books
3 23 400 2,380.00 Books
1 24 352 5,095.00 Books
8 25 32 190.00 Books
12 26 70 416.00 Books
Click to
display
menu
10
-
7/29/2019 5-131_02_2
13/26
Introduction to Access 2003 Doc. 5.131
Sort the table in ascending order on the Value field. What is the fourth value?
6 Queries
6.1 What are Queries?You use queries to view, change, and analyze data in different ways. You can also
use them as the source of records for forms and reports. The examples that we will
build today is called a Select Querybecause we are selecting fields and records from
the database.
The steps in designing a query are:
Decide on the type of query to design Add the tables that contain the fields to be displayed
Add the fields which contain the data to be displayed Add any criteria you want to use. Criteria are instructions that you use to tellAccess which records to display. When you come to design your own
databases you should use the on-line help to search for examples ofcriteria
expressions
6.2 Query Wizard
(SMS Section 4.3)
) A query creates a dynamic subset (called a dynaset in database terminology) of those
records in the underlying tables that satisfy the criteria specified in the query.
The next task is to create a query that finds allthe records in the Contacts table.
We will then see how to apply criteria to the query to return dynasets.
Exercise 8 Create a simple select query
In the database window select the Queries button
Double click on Create query by using wizard. The query wizard starts
In the box labelled Tables/Queries select Table: Contacts from the dropdown menu
Click on >> to move allthe fields from the Available fields list to theSelected fields list
Click on Next >
In the next step select Open the query to view information (it should beselected by default) and click on Finish. Your query will return data and should
display the data that you entered into the contacts table
In the above example you moved all the available fields from one table. However, if
you only need some fields
Click on the field name in the Available fields list
Click on > to move it to the Selected fields list Repeat this for all the fields that you need
11
-
7/29/2019 5-131_02_2
14/26
Doc. 5.131 Introduction to Access 2003
If you need fields from another table or query select the other table or queryfrom the Table/Query list
If you change your mind about a selected field, select it in the Selected fields listand click on < to return it to the Available fields list.
6.3 Adding criteria to a query(SMS Section 4.4)
You enter criteria in the criteria cell, that is the intersection of a row and a column.
You may use a text value as a selection criteria; e.g. a persons surname or you may
use mathematical values e.g. >=10
Exercise 9 Select a contact
In the query window switch to design viewby clicking on the Designview button on the tool bar (see right)
In the Criteria Row and Surname column type Parkinson. Your queryshould look like Figure 6-1
Figure 6-1 Select Query example
Query by Example
(QBE) grid
Run the query by clicking on the Run button on the toolbar at the top of thescreen (see right)
Close your query by clicking on the close button (x) at the top right corner ofthe query window. (When asked if you want to save changes click on No.)
6.4 Joining tables in a query
You can also create a query that uses more than one table. For example, if we want
to find all the orders made for institutions with more than 10,000 students we need
to know the institution and number of students, which is held in the Contacts table,
and the order numbers which are held in the Orders table. The institution code in
12
-
7/29/2019 5-131_02_2
15/26
Introduction to Access 2003 Doc. 5.131
both tables allows us to link together the information. In database terminology it
identifies a relationship between the tables.
When working with several tables,designers often use the Table.Field notation to
clarify the specification. In the following exercise you will see this notation used; for
example Contacts.Institution Code refers to the Institution code field in the
Contacts table.
Exercise 10 Joining tables in a query
In the database window double click on Create Query in Design view
In the Show Table window click on contacts, then click on add to add thetable to the query.
Do the same for orders, then click on Close
A query design window appears. Add the following fields by double clicking onthe field name
Contacts.Institution Code (i.e the institution code field from the contacts
table)
Contacts.Institution
Contacts.num students
Orders.Institution code
Orders.Order num
In the Criteria row, Num students column type >10000
Save as Large Institutions Query. Your query in design view should look likeFigure 6-2
Figure 6-2 Joining tables query
Run the query. The results should look like Figure 6-3
Figure 6-3 Results of Large Institution Query
13
-
7/29/2019 5-131_02_2
16/26
Doc. 5.131 Introduction to Access 2003
Close Large Institutions Query
) If you do not want to display a field then clear the check box in the Showrow inthe 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 yourchosen field. You can select a sort order from the drop down menu.
6.5 Calculated criteria
You can group records based on fields that have the same value. You can calculate
mathematical functions such as totals or averages. To do this you need to add the
Totals row to the design view window.
Exercise 11 Calculate the sector Average
In the database window open a new query in design view Using the techniques that you learnt in Exercise 10, add the contacts table, then
add the fields Edu Sectorand Num Students
Click on the Totals button on the toolbar (hint: it looks like a ). A totals rowappears in the QBE grid
In the Edu Sectorfield choose Group By from the totals menu
In the num students field choose Avg (average) from the totals menu
Run the query
Save the query as Sector Average Query
Exercise 12 Calculate the sector totals
Use the technique that you learnt in Exercise 11 to calculate the total number ofstudents (sum) for each educational sector.
6.6 More practice at working with queries
You will find sample solutions to these exercises in the sample database
Q:\Samples\Access2k\sms contacts.mdb.
14
-
7/29/2019 5-131_02_2
17/26
Introduction to Access 2003 Doc. 5.131
Exercise 13 Create an Orders query
Use the technique that you learnt in Exercise 8 to create a select query titledOrders Query, based on the Orders table, which will list all the fields in the orders
table. Experiment by using the criteria =Books and =CD in the Order Type
field to select all the book orders or all the CD orders.
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.
Exercise 14 Find maximum number of books
Create a query titled max book order query that finds the record for thelargest number of books.
Exercise 15 Select CD Renewal dates
Find all the CD orders with renewal dates after 31/12/01. Save the query as CDRenewal Query.
Exercise 16 find average book order
Find the average number of books ordered. Save the query as avg book ordersquery
Exercise 17 Find lowest value order
Find the order for books with the lowest value. Save the query as min bookvalue query. Hint you will need to include a criteria that displays only orders
for books.
7 Forms
7.1 What are forms?
Forms provide an alternative and more accessible way of presenting and entering
data than using a datasheet. The form permits the viewing of a single record at atime, and the design of the form may be easily customised to suit your requirements.
Other advantages of forms are:
they are familiar, as they are similar to a paper form it is often quicker to enter data using a form rather than the datasheet data can be presented in a more attractive and accessible manner and can include
graphs and pictures
15
-
7/29/2019 5-131_02_2
18/26
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.
7.2 Create a form with Form Wizard
(SMS section 5.1)We will create a columnar form based on the contacts table, using the Form Wizard.
The contacts table is the record source of the form, i.e. the source from which it
retrieves data.
Exercise 18 Create a form with Form Wizard
In the database window select the Forms button
Double click on Create form by using wizard. The form wizard starts
In the box labelled Tables/Queries select Table: Contacts from the dropdown menu
Click on >> to move allthe fields from the Available fields list to theSelected fields list then click on Next >
Select columnarlayout and click on Next >
Select standard style and click on Next >
Type Contacts Form in the title box, select Modify the form design andclick on Finish
7.3 Entering Data with a form
To enter data using the form you simply type the data into the boxes, using the
mouse or clicking on the TAB key to move to the next field.
7.4 Modify the form design
(SMS Section 5.2)
InAccess jargon everything is called an object. Tables, Forms, Queries and Reports are
all Objects. The labels, boxes, text boxes and other items on a form or report are a
special type of object known as a control. Before you can do anything with an object
you have to select it, by clicking on it when you are in design view. On Forms and
Reports you can makeMultiple Selections; that is you can select several objects at
once.
All objects have properties that you can edit.
If you cannot see theproperties window then
click the right mouse button
and choose Properties
from the menu that drops
down. The propertieswindow
is displayed (see right). In
the title bar is the name of
the object that you have
selected (the form in thisexample).
16
-
7/29/2019 5-131_02_2
19/26
Introduction to Access 2003 Doc. 5.131
To change a property click in the relevant field. Some properties will display adrop 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 SHIFTkey andclick on each object in turn.
) To select several objects that are not next to each other hold down the CTRL key andclick 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 doanything with it. For example, you must select a block of text in Word before you
can copy it
Exercise 19 Modify a form
The form should now be in design view. If it is not then switch to designviewby clicking on the Design view button on the tool bar
Click on the label Surname. Hold down the SHIFT key and click on the other
labels (forename, edu sector, Institution, Num Students and Institutioncode). Your form should now look like Figure 7-1
Figure 7-1 Selected objects on a form
Still holding down the SHIFT key display the properties window (as explainedabove). The properties window should have the titleMultiple Selection
If the Format tab is not on top click on it to select it
Click to select Fore Color
(scroll down the window ifyou cannot see it). A
17
-
7/29/2019 5-131_02_2
20/26
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
7.5 Create an object on a form
(SMS section 5.2)
You can add objects such as labels to your forms. These objects are known as
controls.
You create controls by clicking once on an object from the Toolbox(see
right) and clicking and dragging the mouse pointer to draw it on the
form. When you point (do not click) to a control the name of the
control appears as a small yellow label. If you cannot see the Toolbox
then, in form design view, select toolbox from the view menu.
We will start by creating a simple label on the form. However, some
controls are more sophisticated. For example you can use a combo box
to display a menu of items that the user is allowed to select (see SMS
section 5.3). You can use a calculation as the control source from which a text box
takes its data.
Exercise 20 Add a control to a form
Make sure that you have the Contacts form open in design view. Position themouse pointer between the headersection and the detailsections on the form
(see Figure 7-2). The pointer will change to a bar with a double arrow across it
Figure 7-2 Header/Detail sections
Position
cursor here
Drag the detail section down so that a gap of about 1cm appears between theform header and detail sections.
Click on the label tool on the tool box to select it. To find the tool move thecursor along the tool bar without clickingon 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, thendrag to draw a box. In the box type Software made Simple Contacts
18
-
7/29/2019 5-131_02_2
21/26
Introduction to Access 2003 Doc. 5.131
In the Format section of the properties box set the Text align property tocenter, font size to 10 and font weight to semi bold. Set the fore colour
to a colour of your choice
Save your changes
7.6 More practice at working with forms
Exercise 21 Create an orders form
Using the Orders table create a columnar form using the Form Wizard. Title theform Orders Form
8 Reports
(SMS Section 6)
Reporting is the way in which you choose to present the contents of your databaseas printed pages.
Reports enable you to select which fields will be printed out and what datashould be included. Reports can also summarise data in various ways
Microsoft Access 2003 gives you the opportunity to design the layout of aparticular 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 aquery 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 couldcreate 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.
Exercise 22 Create a report
In the database window select the Reports button
Double click on Create report by using wizard. The report wizard starts
In the box labelled Tables/Queries select Table: Contacts from the dropdown menu
Click on >> to move allthe fields from the Available fields list to theSelected fields list
Click on Next >
In the grouping window select Edu sectorfrom the list of fields & click on >Your window should now look like Figure 8-1
Click on Next >
19
-
7/29/2019 5-131_02_2
22/26
Doc. 5.131 Introduction to Access 2003
Figure 8-1 Group by Edu Sector
In the sorting window select Institution in the box labelled 1 and Surname inthe 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. Clickon 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.
8.1 Modifying a report
(SMS Section 6.2)
A basic report is divided into three sections
Page Header
Page Footer
Contain data that will appear at the top or bottom of each page of
the report. You might use this to include information about the
source of the report, the date it was completed or the page
number.
DetailThe most important section since any fields added here displaythe actual information from the database for every record in the
table or query on which the report is based.
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
-
7/29/2019 5-131_02_2
23/26
Introduction to Access 2003 Doc. 5.131
Exercise 23 Modify a report
Switch to design view by selecting it from the View button on the toolbar
Use the same technique you previously used to select labels in the contacts formto select all the labels in the page header section of the Contacts Report
Change the Format property Text Align to Center Save your changes
Preview your report by clicking on the view button on the toolbar
8.2 More practice at working with reports
Exercise 24 Create Value of Orders Report
Using the Orders table create a report, grouping the fields by InstitutionCode
Sort the value field in ascending order
Use the Summary Options button on the sort window to display the Sumoption of the Value field
Select layout Align Left 1 and display the report in landscape format
Choose a suitable style for your report
Give your report the title Value of Orders Report
You may wish to experiment with different styles, layouts and summary options.
SMS section 6 gives you some ideas about what you can do withMicrosoft Office
2003. In the following section we will consider how you can combine components of
Microsoft Office 2003 to produce customised documents.
8.3 Mail Merge
AlthoughMicrosoft Access 2003 is good for producing tabulated reports, there will be
occasions when you need something more flexible thanAccess. TheMicrosoft Office
suite of programs allows you to combine the data management features ofAccess
with the formatting and layout features ofWord, using a feature calledMail Merge.
Exercise 25 Mail Merge with Word
Make sure that the Contacts table is not open
In the database window select the Contacts table by clicking on it once do notopen it
Move the cursor along the tool bar without clickingon the buttons. You will see alabel appear to indicate the function of the button. This is called Hover Help
When you have located the Office Links button click on it and select Merge itwith Microsoft Office Word
In the Mail Word Wizard dialogue box select Create New Documentand click on OK
WhenMicrosoft Wordstarts type Dearfollowed by a space
You should be able to see the mail merge toolbar if not, choose View Toolbars Mail Merge
21
-
7/29/2019 5-131_02_2
24/26
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). Youwill see a place marker 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
Please find enclosed an evaluation copy of the latest version of
Software Made Simple material on CD-ROM. We can also supply
this material in book form.
Yours Sincerely
Simon Simple
Use Hover Help to locate the button Merge to New Document. When youclick on this button Wordwill generate a set ofform letters, based on yourAccess
data source. The names of the people in the contacts table have been substituted
for the place markers in your masterdocument. This document may be printed
9 Relationships
9.1 Why use Relationships
In the first session we discussed the tables needed for the database and introduced
the idea ofrelationships between the entities (mapped to tables) in the database.
We have seen that by using the Institution Code as the primary keyin the
Contacts table and as a foreign keyin the Orders table, it is possible tojoin data
from the two tables into a dynaset using the Large Institutions Query.
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)
Table 5 SMS Orders
Field Name Data Type
Order Num Autonumber
Institution Code Number
Surname Text
Forename Text
Edu Sector Text
Institution Text
Num Students NumberNum Books Number
22
-
7/29/2019 5-131_02_2
25/26
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. Foreach 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 anorder 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.
9.2 Types of relationships
Microsoft Access 2003 can handle two types of relationships:
One to Many relationship a record in one table can be matched to many recordsin the second table. However, the record in the second table can only be related
to one record in the first table. For example a site contact (identified uniquely
by the institution code) can place many orders. But each order is associated with
only one institution
One to One relationship a record in one table can be matched to no more than
one record in the second table, and vice versa There is a third type of relationship between entities. That is aMany to Many
relationship. In a many-to-many relationship, a record in Table A can have many
matching records in Table B, and a record in Table B can have many matching
records in Table A. This type of relationship is only possible by defining a third
table (called ajunction table) whose primary key consists of two fields the
foreign keys from both Tables A and B. A many-to-many relationship is really
two one-to-many relationships with a third table.
9.3 A sample database
We will now use aMicrosoft Access 2003 database template to build a rather more
complicated database than the simple example that we have looked at so far.
Exercise 26 Create a database using a wizard
OpenAccess
Close any databases that you have open and select New from the File menu
In the task pane, click on under Templates
Click on the Databases tab
From the database templates select Event Management and click on OK
In the File New Database dialogue box click on create
23
-
7/29/2019 5-131_02_2
26/26
Doc. 5.131 Introduction to Access 2003
As the database wizard takes you through the steps click on next > until it isfinished
After a few minutesMicrosoft 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.
Events.eventid is related to Registration.eventid by a one to many
relationship (shown as 1 to ). Attendees.attendeeid is related to Registration.attendeeid by a one to
manyrelationship (shown as 1 to ). The Registration table is thejunction table used to model the many to many
relationship between Events and Attendees. Attendees can attend one or
more events, events are attended by one or more attendees. Registration
relates an employee to an event
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 studentsand 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 becauseMicrosoft Access 2003 uses American masks
Create a query and generate a report to list the names of all the students whoare studying database design
There is a sample solution to this exercise in
Q:\samples\access2k\students in classes.mdb
9.4 Finding out More about Database Design
The critical factor for successful database design is to get the design of the tables and
relationships right. This takes practice. A recommended book on relational database
design is
Peter Domanski & Philip Irvine,A Practical Guide to Relational Database Design,
Domanski-Irvine Book Company, ISBN 9526043 02. See web page
http://www.personal.u-net.com/~dibookco/rdbms.htm
http://www.personal.u-net.com/~dibookco/rdbms.htmhttp://www.personal.u-net.com/~dibookco/rdbms.htm