Sunteți pe pagina 1din 82

Microsoft Access Tutorial

Lesson 1: General Introduction .......................................3


Introduction......................................................................................................................................3
Database Terminology......................................................................................................................3
Starting Ms Access...........................................................................................................................5
Designing a Database.......................................................................................................................5
Creating a New Database.................................................................................................................6
Exiting Ms Access............................................................................................................................7

Lesson 2: Databases and Tables.......................................8


Opening an Existing Database..........................................................................................................8
Creating Tables.................................................................................................................................9
Creating relationships between tables.............................................................................................16
Adding Records to a Table.............................................................................................................20
Deleting Data in a Record..............................................................................................................21
Changing the width of a column/Moving a column........................................................................22
Finding Records.............................................................................................................................23
Filtering and Sorting Records.........................................................................................................25
Sorting............................................................................................................................................26
Exercise..........................................................................................................................................28

Lesson 3: Queries..........................................................32
Introduction to Queries..................................................................................................................32
Creating and Saving Queries..........................................................................................................32
Complex Queries............................................................................................................................34
Creating Complex Queries.............................................................................................................35
Print the Resulting Data in a Query ...............................................................................................37
Query Types...................................................................................................................................38
Creating Total Queries....................................................................................................................38
Exercise..........................................................................................................................................41

Lesson 4: Forms............................................................42
Features of a Form.........................................................................................................................42
Creating Forms Using the Form Wizard.........................................................................................42
Creating Forms Using Auto form...................................................................................................43
Creating a Form Using Design View..............................................................................................45
Opening a Data Entry Form...........................................................................................................45
Customising a Form.......................................................................................................................45
Object Linking and Embedding (Ole).............................................................................................46
Creating Unbound Controls...........................................................................................................47
Calculated Unbound Controls........................................................................................................48
Data Protection..............................................................................................................................53
Editing Data in a Form...................................................................................................................53
Exercise..........................................................................................................................................54

Lesson 5: Reports..........................................................56
Creating Reports Using a Wizard...................................................................................................56
Creating Reports Using Design View.............................................................................................62
Page 1 of 83
Sections of the Report....................................................................................................................64
Previewing and Printing Reports....................................................................................................65
Reports Based In Multiple Tables..................................................................................................68
Report Printing...............................................................................................................................71
Exercise..........................................................................................................................................71

Ms Access Project.........................................................................................................................72

Page 2 of 83
Introduction to Ms-Access

Lesson 1: General Introduction

1.0 INTRODUCTION
Microsoft Access is a Windows based application. It helps in storing information about different
subjects in separate tables. It allows for creation of forms, which automate tasks, queries and
reports that help analyse data.
Benefits
1. Faster Retrieval of information
2. Analysing data using queries and producing reports for management purposes
3. Security using a Login password to prevent unauthorised access of data
4. Consistency because data is stored in a central place and is not scattered in different places
5. Data sharing by people different departments through the Local area network(LAN)

The main focus of Ms Access is the Tables otherwise known as files. Tables Consist of Fields
(attributes) and are used to store data e.g An Employees Table.

Database Terminology

Data
The material (Stuff) that Access stores, organises and manages for you

Fields
The place where data is placed within the database is called a field. One field holds one piece of
data. If you are storing student details, possible fields would include Name, Admission number,
Age…

Records
All the fields for one student constitute a record, Records ensure which name relates to which
admission number, age

Table
A collection of records that describe similar data is called a table. A database for student details
could have tables for admission information, fees, and exams…

Page 3 of 83
Index

An index speeds up queries on the indexed fields as well as sorting and grouping operations. For
example, if you search for specific employee names in a LastName field, you can create an index
for this field to speed up the search for a specific name.

Internally, an index is implemented as a look up list much like the Index you use to find
information about a particular item in a book.

Primary Key

A field created in a table to UNIQUELY identify records. For example the NationalID number
field has a unique value for every employee and therefore can be used as a primary key.

Primary keys are needed to aid in searching for records. This is because a field such as the
Employees Name is likely to contain similar names for different people. This means that it is
more prudent to invent a series of codes (Usually Numerical) to identify the employees uniquely.

Page 4 of 83
1.01 Starting MS Access

Start windows and then click Microsoft Access icon to run the application or Select the program
from the Program listing in the Start menu as shown below

Designing a database

A database is a collection of related data.

1. Determine the purpose of the database. This helps in deciding the facts to be stored.
1. Determine the tables. Divide the information into separate subjects, such as employees or
orders. Each subject will be a table in the database.
3. Determine the fields. Decide what information to store in each table. Each field is displayed as
a column in the table.

NOTE
When you create a Microsoft Access database, you create one file that contains the data and table
structures as well as the queries, forms, reports, macros and modules.

Page 5 of 83
1.02 CREATING A NEW DATABASE
Once you have loaded the Ms Access application, you will see a dialog similar to the following:
(If it is not visible: From ‘View’ Choose ‘Tool Bars’ then ‘Task Pane’)

The Part Marked ‘C’ enables you to create a blank new database

NB: A database file must be saved before it can be used and you will be prompted to save the file
first i.e

To create a new database:


a) Choose ‘Blank Database’ as shown in ‘B’ on the Picture above.

Alternatively:

b) You may click on the ‘New’ Icon ( )

Either way you will get the ‘Save’ dialog box as shown below. Type the name of the Database
and click on the ‘Create’ Button.

Page 6 of 83
NB
The database window is named after the name of the database that you have created. Thus:

1.3 Exiting Ms Access

Page 7 of 83
1. Before exiting Ms-Access, ensure that all your tables and other database objects
(new or ones to which you have made cahges) are saved, if they are not saved you
will get a dialog similar to the one below

2. You need to be sure of the choice that you will make since it may have implications
on the data that you have stored in the database
3. Once all database objects are closed, you may close the database window by
clicking on the exit ( ) button
4. Exit ms-Access by choosing “Exit” from the “File” menu

Page 8 of 83
Lesson 2: Databases and Tables
2.01 Opening an Existing Database

The part marked ‘A’ (See Picture Above) shows a list of existing databases that you opened in the
recent past. This list will be different for different system users (If you are using Windows XP or
2000). By clicking on either of the names in the list, you will be able to open the chosen database.

To open a database that is not listed, you may choose ‘Open’ from the ‘File’ menu i.e.

You may also


use the ‘Open’
Icon ( )

Page 9 of 83
Either way you will get the ‘Open’ dialog box from where you must choose the source of the file
i.e.

Choose the file you want to open and click on the ‘Open’ button

2.02 creating tables

TABLES

Creating a new table


1. Determine the fields you would like to include in the table
2. Select the Tables option and click on the New button
3. Select Design view
4. Tables are created when you want to store information that is not stored in an already existing
table e.g. when you want to customers and you only have a ‘Products’ table.

Page 10 of 83
Click on the ‘OK’ Button as shown above.
This results in the display of a design window for the new table. It is here that you define the
fields associated with this table; their names, data types and descriptions. Each field within a table
has a name. This name can be up to 64 characters long, and can include letters, numbers and
spaces.

Page 11 of 83
The following is a summary of all the field data types available in Microsoft Access, their uses,
and their storage sizes.

Field Properties

Text
Stores text or combinations of text and numbers, such as addresses, numbers that do not require
calculations, such as phone numbers, part numbers, or postal codes of size up to 255 characters.

Memo
Stores lengthy text and numbers, such as general notes or detailed descriptions. Memo fields hold
up to 64000 characters of information.

Number
Numeric data to be used for mathematical calculations, except calculations involving money (use
Currency type). Set the Field Size property to define the specific Number type.

Date/Time
Stores Dates and times

Page 12 of 83
Currency
Currency values. Use the Currency data type to prevent rounding off during calculations. Accurate
to 15 digits to the left of the decimal point and 4 digits to the right.

AutoNumber
Unique sequential (incrementing by 1) or random numbers automatically inserted when a record
is added.

Yes/No
Fields that will contain only one of two values, such as Yes/No, True/False, On/Off.

OLE Object
Objects (such as Microsoft Word documents, Microsoft Excel spreadsheets, pictures, sounds, or
other binary data), created in other programs using the OLE protocol, that can be linked to or
embedded in a Microsoft Access table. You must use a bound object frame in a form or report to
display the OLE object.

Field properties

Depending on the nature of the contents of your field, a certain level of control can be achieved
such that a field will accept what it has been programmed to have. The following options are
offered:

FIELD SIZE
Allows entry of field size for Text data type For example, if the standard length of names is 25
characters, you may use this property to limit the number of characters entered into such a field to
25. In this case, if there are existing names longer than 25 characters then they will be truncated to
25.

For numeric data types, you choose the field size by selecting from a drop-down list. Field size
does not apply to the Date/Time, Yes/No, Currency, Memo or OLE object data type.

FORMAT
Allows selection of a predefined format in which to display the values in the field from the drop-
down combo list applicable to the data type that you chose (Except Text). One can also customise
a form of presentation of data. E.g. to have a code appearing before every telephone number you
wish to enter, select the relevant field and set the format:
“02-”000000 (This gives the code for Nairobi)

Page 13 of 83
DECIMAL PLACES
Can select specific number of decimal places from the drop-down combo list, and applies only to
number and currency fields.

INPUT MASK
Helps put a mask for controlling the entry e.g. setting a limit especially to the entry of numeric
fields:
000000 Will allow a six digit number no more than that or less.
999999 Will allow six or less digits.

CAPTION
This is a name used (other than the field name) to appear in the field name header button in Table
datasheet view.

DEFAULT VALUE
Allows setting of a value, which will automatically be entered into the field when a new record is
added to a field. E.g. Setting default date as current date: =Date()

VALIDATION RULE
Validation rules test the value entered in a field against set criteria. E.g.
Like “Jordan” : Will only accept the word Jordan
<10000 : Any value less than 10000
>=5000 AND <=10000 : Entry of between 5000 and 10000

VALIDATION TEXT
Provides a message. It appears in response to violation of validation rule. It must be typed in
earlier.

REQUIRED
Controls the entry of important fields. A YES option ensures a field is not left blank and is
equivalent of typing IS NOT NULL as a field validation rule (Not necessary for primary keys
since Access does not allow null value in primary key fields).

ALLOW ZERO LENGTH


Applies to the Text and Memo field data types. Setting the value of Allow zero length property to
Yes and the Required property Yes, the field must contain at least one character. A Zero-length
string
(“ “) and the Null value are not the same.

Page 14 of 83
INDEXED
[Yes (Duplicates OK)] - Gives sorted indexed field and can allow data duplicates. [Yes (No
duplicates)] - Gives sorted, indexed but cannot allow data duplicates . It’s not available for Memo or
OLE data types.

NEW VALUES
Applies only to AutoNumber fields. Access can increment the Autonumber field by one for each
new record, or fill in the field with a randomly generated number, depending on the new values
property setting that you choose.

NB For more details on fields and Field properties, press F1 to access help.

To switch between ‘design’ and ‘datasheet’ views:


1. Move to the ‘View’ option
2. Choose the appropriate view i.e. Design or Datasheet

Example of Table (Design View)

In this view you can make changes to the database design e.g. adding new fields, changing field
types and or/ attributes
Once you finish designing the table, click on the save icon ( ), the following dialog comes up

Page 15 of 83
Type an appropriate name e.g. ‘Customers’ then click on the ‘Ok’ Button ensure that the new
name is not given to an existing table. You will be prompted to define a primary key IF you have
not already defined one i.e

1. If you answer ‘Yes’ the table will be saved but Access will add a new field named
‘ID’,‘ID1’…. Of type ‘AutoNumber’ and make it to be the primary key.
2. If you answer ‘No’ the table will be saved with no primary key defined i.e. ‘As it is’
3. If you answer ‘cancel’ the new table will not be saved.

Example of Table (Datasheet View)

In this view you can add new records, delete edit or existing records

a b c d e

a) Moves to the FIRST record.

Page 16 of 83
b) Moves to the PREVIOUS record.
c) Moves to the NEXT record.
d) Moves to the LAST record.
e) Creates a NEW record.

2.03 Creating relationships between tables


 A relationship determines how to link information from many tables so that Microsoft
Access can determine knows how to relate the information. A join compares the values of a
field in one table with the values in the joined field of the other table. The result is a link of
the records in both tables wherever the values of the joined fields equal.
 When it finds matches it combines those two records and displays them as one record in
the query’s results. If one table does not have a matching record in the other table, neither
record appears in the query’s results.

NB

 The fields used to join two tables must be of the same data.
 The joins created during the query apply only for that query.
 In some instances, Access automatically creates joins e.g. If you add two tables to a query
and the tables each have a field with the same name and data type and a relationship
has already been created between the tables;
 If one of the join fields is a primary key. If Members No. in the Members table was a
primary key, then a join would have automatically been created between the members and
have automatically been created between the Members and Rental tables. Primary keys
are usually shown in boldface.

After setting up tables to store related information, you need a way of linking the details in the
different tables. Those tables should be already normalized.

Procedure
1. You cannot create or modify relationships between open tables, Close any open tables.
2. From the Toolbar click on the relationships icon

Relationships

OR
From the Menu Bar Choose “Relationships” from the ‘Tools’ menu

Page 17 of 83
3. If the tables you want to relate are not displayed, choose ‘Show Table’ option from the
“Relationships” menu.

4. Select the required tables then click on the button ‘Add’. Resize the table window if
necessary so that you can be able to see all the fields in it.

5. Drag the field that you want to use to establish the relationship from one table to the
related field in the other table. In the above example drag ‘CategoryID’ from the
‘Categories’ table to CategoryID’ in the ‘Products’ table]

6. When you release the mouse the following dialog box appears:

Page 18 of 83
In the dialog box you confirm that the field use to establish the
relationship is correct on both tables.

Types of relationships
 One to One
This is where one record in One Table can have only one related record in
another table. For example a Man Can have Only One Wife
 One to Many
This occurs where one record in a Table (Parent Table) can have many related
records in another table (Child Table).

Page 19 of 83
 Many to Many
One record in either Table A or Table B can relate to many records in the
other table. For example, suppliers can supply many products, and the
products can be supplied by many suppliers.

NB: If the relationship exists between two linked tables, the relationship is
termed as External

Microsoft Access checks the data available in the tables and suggests the type of
relationship that would be suitable.

7. To change the relationship created without exiting, click Create New.

8. Enter the details of the relationship as shown above then Click OK


9. Otherwise click on Create.

10. The relationship is indicated by the join line between the two tables
11. Save and close the relationships so that next time the database is opened the
relationship will not have to be created afresh.

Referential Integrity

Page 20 of 83
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. Once referential integrity is enforced
then:
 You can't enter a value in the foreign key field of the related table that doesn't exist in
the primary key of the primary table.
 You can't delete a record from a primary table if matching records exist in a related
table. For example, you can't delete a category record from the categories table if there
are products assigned to the category in the products table.
 You can't change a primary key value in the primary table, if that record has related
records. For example, you can't change the CategoryID in the categories table if there
are Products assigned to that Category in the Products table.

Editing Relationships between tables

Deleting Relationships
1. Click on the Relationship line for the relationship you want to delete (The
line will turn bold when it is selected).
2. Press the Delete key on the keyboard.
3. Confirm that you want to delete the relationship.
4. Click Yes

Modify Existing Relationships


1. Double-click the relationship line for the relationship you want to edit.
Set the new relationship options.

2.04 Adding Records

You can add records in a table only when you are in the Datasheet View. It is not possible to add
data in an ‘AutoNumber’ field. Move to the blank record showing on your table and enter your
data, as shown below

Page 21 of 83
You may find it easier to add a record after clicking the new ‘button’ ( )

1.05 Deleting Data in a Record.


Access allows you to EDIT or even DELETE the contents of a record. To delete or edit
1. Highlight the text (e.g Maithya as listed above)
2. Press the Delete key OR Type the new text you would like to replace with
NB. If you delete or Edit by mistake you may use the UNDO command from the Edit menu or
the undo icon ( ), However a full RECORD deletion cannot be reversed.

Page 22 of 83
To delete the entire table,

a) Determine that the table contains data that you do not require any more.
b) Ensure that the table is not open either for Design or data entry.
c) Highlight the table you want to delete then press the ‘Delete’ key answer ‘Yes’ to the
question below

2.06 Changing the width of a column/Moving a column.

This is usually done to enable the user to view all data in a particular column. The
column may contain data that is not entirely visible due to its length e.g. the ‘Title’
field below has been expanded

To Expand:
 Move the mouse pointer to the point at the end of the field name (Title) and at the
beginning of the next field name. The mouse pointer changes to a Thick Cross.
 Press the left mouse button and drag in towards the right.
To move the column
 Move the mouse pointer to the top of the column, on the field name so that it changes
to a thick arrow pointing downwards.
 Click once to highlight
 Press and hold the mouse pointer on the field name then drag to the desired position
NB: This does not change the position of the field in design view

Page 23 of 83
2.07 Finding Records

You may sometimes need to find records in your table, for example you may require to change the
salary of one of your employees say “Suyama” To Find a record:
f) Open the table in ‘datasheet’ view
g) Move to the field on which you would like to perform the search e.g. ‘Last Name’
h) From the ‘Edit’ menu choose ‘Find’
i) The following Dialog Comes up

j) Type the name that you want to search in the ‘Find What’ list box
k) Click on the ‘Find Next’ button

l) If this is not the record you are looking for, click on ‘Find Next’

Find dialog box Options:


a) Match
Click on the drop-down arrow to display a list of search locations

Page 24 of 83
b) Any Part Of The Field
Searches for any occurrence of the text string. For Example, searching for ‘Smith’ finds
‘SmithSonia’ and ‘JohnSmith’
c) Whole Field
Recognise a match only when the text string matches the complete contents of the field.
d) Start of Field
Searches for the text string at the beginning of a field for example searching for ‘Smith’
finds ‘SmithSonia’ not ‘JohnSmith’

e) Search
Click the drop-down arrow to display a list of search directions.
f) All
Searches through all records in the database
g) Up/Down
Searches either downwards or upwards from the current position

2.08 Deleting records

Occasionally, you will need to delete unwanted records from your file eg those of customers who
are no longer shopping with us.

a) Open the table in Datasheet View


b) Highlight the record to be deleted as shown below

c) Press the ‘Delete’ key


d) When you are prompted as shown below, choose ‘Yes’

Page 25 of 83
e) The selected record will be deleted permanently.

2.09 Filtering and Sorting Records

Filtering

Filtering allows you to view a set of records depending on some criteria that you may set

Steps:
4. Select “Filter” From the “Records” menu then select “Advanced Filter/Sort”. The
filter window appears as shown below:

5. Choose the field(s) by which you want to apply the filter by clicking on the Combo
Box button (shown at the point where the cursor is). These fields will also be
displayed.
6. You may optionally choose a sort order (Ascending or Descending)
7. Type in a criteria to be used, then “Right Click” and choose the “Apply Filter”
option

Page 26 of 83
8. To redisplay the entire table, click on the “Remove Filter” ( ) button or from the
“Records” menu, choose “Remove Filter/Sort”

2.10 Sorting
You may sometimes require to arrange records in some order e.g. you may arrange them
according to the “LastName”. This may be useful in determining the highest or lowest value in the
table.
Steps:
1. Position the cursor in the field on which you want to sort. E.g. to sort by the lastName,
position the cursor in the lastName field
2. To sort in ascending order (Smallet to Largest) click on the
( ) Sort ascending button

To sort in ascending order (Largest to Smallet) click on the


( ) Sort descending button

Page 27 of 83
Exercise
1. Create a database called Travellers
2. Create the following tables in the database. (Primary Keys are Underlined)
3. Set any other properties that you want for your field for data automation.
a) Drivers
Fields Data type
Drivers_ID Number
FirstName Text
LastName Text
Address Text
Date_Of_Birth Datetime
Hire_Date Date/Time
Salary Currency
b) Vehicles
Fields Data type
Vehicle_IDNumber
Reg_No Text
Capacity Number
Make Text
Type Text
Date_Acquired Date/Time

c) Shifts
Fields Data type
Shifts_ID Number
Drivers_ID Number
Vehicle_ID Number
Route_No Text
Shift_Name Text

Page 28 of 83
d) Routes
Fields Data type
Route_No Text
Distance Integer
Fare Currency
Destination Text
4. Define the appropriate relationships for your tables.
Enter The Information below in your tables already designed
Table: Drivers
Drivers_ID Last Name First Name Birth Date Hire Date Address
12/8/194
1
Aketch Nancy 8 5/1/1992 P.O. Box 4501 Kisumu
2/19/195 8/14/199
2
Mutunga Andrew 2 2 P.O. Box 6733 Mombasa
8/30/196
3
Kasavuli Janet 3 4/1/1992 P.O. Box 6747 Maragoli
9/19/193
4
Thatcher Margaret 7 5/3/1993 P.O. Box 35667 Nairobi
10/17/19
5
Mulumba Steven 3/4/1955 93 P.O. Box 644 Bungoma
10/17/19
6
Wamalwa Michael 7/2/1963 93 P.O. Box 876 Bungoma
5/29/196
7
Koskei Robert 0 1/2/1994 P.O. Box 260 Litein
Chepkuru
8
i Laura 1/9/1958 3/5/1994 P.O. Box 8955 Nakuru
1/27/196 11/15/19
9
Kitui Anne 6 94 P.O. Box 754 Bungoma
1/11/200 P.O. Box 1342 00400
10
Mutuku Caroline 3/5/1973 0 Nairobi
Nyamban 12/6/197 6/15/199
11
e Walter 5 9 P.O. Box 7803 Kitui
6/13/197 P.O. Box 11789 00400
12
Wasike Levy 8 8/4/2003 Nairobi

Drivers are paid a uniform salary of Sh. 12000/-. Update your table to reflect these
details.
Table: Routes
Route NO Distance(Kilometers) Fare(Ksh.) Destination
305A 384 600.00 Nyeri
305D 288 450.00 Muranga
290B 589 550.00 Kakamega
290A 512 550.00 Kisumu
514B 189 300.00 Nakuru
519 487 400.00 Kitale
514A 350 400.00 Eldoret
609A 615 500.00 Mombasa
609B 710 800.00 Malindi
609C 542 500.00 Voi
1011A 1241 1500.00 Kampala
1011B 1005 1500.00 Jinja
1012A 950 1000.00 Mbale

Page 29 of 83
Dar-e-
2011 1600 1800.00 salaam

Page 30 of 83
Table: Vehicles
Capacit Date_Acquire
Vehicle_ID Reg Number Make y Type d
1 KAP 893J SCANIA 310HP 67 BUS 1/25/2003
2 KAK 788K ISUZU 62 BUS 5/11/2000
3 KAD 655A ISUZU 62 BUS 6/12/1999
4 KAR 700H SCANIA 310HP 72 BUS 2/25/2004
5 KYW 415 NISSAN DIESEL 55 BUS 6/11/1990
6 KAP 644M TOYOTA HIACE 14 VAN 9/27/2003
7 KAQ 255G TOYOTA HIACE 14 VAN 5/8/2001
8 KAR 214P ISUZU INTERCOOLER 70 BUS 4/2/2004
9 KAL 579C ISUZU 60 BUS 5/13/2000
10 KAQ 192V MITSUBISHI CANTER 25 MINI BUS 9/25/2001
11 KAN 234U MITSUBISHI CANTER 25 MINI BUS 4/8/2002
12 KAP 562L PEUGEOT 505GL 8 VAN 12/18/2003
13 KAQ 894W PEUGEOT 505GL 8 VAN 1/16/2003
14 KAP 012L SCANIA 310HP 70 BUS 4/6/2003
15 KAQ 331K ISUZU INTERCOOLER 70 BUS 5/14/2003
16 KAR 444P SCANIA 310P 72 BUS 2/2/2004

Table: Shifts
Drivers are assigned the following shifts schedules. Add this information in the Shifts table.
Shifts_ID Drivers_ID Route_No Shift Vehicle_ID
1 1 290A DAY 2
2 5 519 NIGHT 3
3 8 514B AFTERNOON 6
4 3 514A MORNING 7
5 7 1011A NIGHT 1
6 10 305D DAY 5
7 6 290B NIGHT 4
9 4 609C DAY 9
10 11 609A NIGHT 14
11 2 609B NIGHT 15
12 9 1012A DAY 16

Page 31 of 83
Lesson 3
3.0 Introduction to Queries

WHAT THEY ARE AND HOW THEY WORK

Queries are used to view, change and analyse data in different ways. They can also be used as the
source of records for forms and reports.

Why use queries?

We need queries when we want to ask ourselves questions about data stored in our tables.

How do they help us?


 In choosing fields
 Choosing records that meet a certain criteria
 In sorting records
 Performing calculations - can create calculated fields and add data to them.

3.1 Creating/Saving Queries

 Open your database


 Select Query option
 Double Click Create Query In Design View

 A list similar to the one shown below will appear.

Page 32 of 83
 Select table to query from list, Add, then Close

This gives QBE (Query By Example) display.

 Select fields you need and drag them to QBE


 Add a criteria to be used in selecting records (if desired) as shown below
 If required, choose a sort order in the ‘Sort’ row. To do this, you must determine which row(s)
will be used for sorting e.g. you may use the ‘FirstName’ field and sort it ascending i.e. names
beginning with ‘A’ then ‘B’ then ‘C’ and so on till ‘Z’

Page 33 of 83
 Save the query, then close it is important to use an Appropriate name to distinguish you
queries later e.g “Employee Names”
 To run the query, ‘Double Click’ on it OR if the Query window is open Click on the ‘Run’
icon ( )

NB. You may choose not to display some fields by removing the ‘Tick’ under the ‘Show’ row e.g.
The field ‘Title’ above will not be displayed

A dynaset (Dynamic view of table) appears after opening the query table saved.

3.2 Complex Queries


Sometimes it is necessary to extract data from more than one table. This is always the case
if your tables are properly constructed. For Example, you may have a ‘Product Categories’ Table
as well as a ‘Products table’, every product belong to a particular category thus ‘Pork, Chicken,
Mutton’ are All types of ‘Meat’ and ‘Cabbages, ‘Sukuma Wiki’ are types of ‘Vegetables’. If you
needed to extract comprehensive ‘Products’ data then you would need to extract it from both
tables.

3.3 Creating Complex Queries


Page 34 of 83
A query can be used to bring together data from more than one table and show the results in a
single datasheet.

Procedure

1. From the Database Window, select ‘Queries’.


2. Create query in Design view.
3. Choose all the tables that contain the information that you need to view in the
query then click on Add.

4. Click on Close to get to the Design grid.

Page 35 of 83
5. All the tables selected are shown in the Design grid. The table windows can be
expanded so that all the fields can be seen.
6. In order to retrieve data from multiple tables, a join (link) needs to be created
between the tables. A join I s a relationship established between the tables by
the use of Join Lines.
7. Before creating any join lines, first establish which fields are common or have
the same information between the tables. These fields must be of the same data
type. From the example above, the field CategoryID in the Categories table is
similar to the field CategoryID in the Products table.

Page 36 of 83
8. To create a join line, drag the field that you want to use to establish the
relationship from one table to the other table. For example, drag the field
CategoryID in the Categories table to the field CategoryID in the Products
table.

NB. If you have already created relationships between your tables, then Microsoft
access creates these joins in the query Grid automatically.

1. If you wish to view a filtered list then Type in the criteria. you may use a
wildcard symbol i.e. the asterisk (*). We would like to get all the products whose
name start with ‘M’ so we type in the criteria as Like "M" & "*"

2. Run the query to view its results.

Save the query using an appropriate name. This kind of query may be used to produce a report.
The resulting report will derive information from the query and therefore from all the tables used
in the query.

3.4 To print the resulting data:


1. From the ‘File’ menu choose ‘Print’
2. To print using ‘Default’ settings, click on ‘Print’ else change the desired options (No Of
Copies, Pages) then ‘Print’

Page 37 of 83
3.5 Query Types
Ms-Access supports various types of queries used to accomplish different functions. These will be
introduced briefly and covered in more detail later.

1. SELECT QUERY
This is a query where a user querying a database selects what to view by the use of a set criteria
entered at the dynaset view.

2. UPDATE QUERY
This query allows some fields within a table to be updated automatically.

3. MAKE TABLE QUERY


This query allows for creation of a new table which can contain records sharing some properties
e.g. A table for all production staff

4. DELETE QUERY

This query allows deletion of records from a table, especially those that have been transferred to
another table.

5. APPEND QUERY

This query allows for joining of tables. These are tables, which may earlier have been separated.

6. CROSSTAB QUERY

This type of query allows you to summarise data in a spreadsheet format. This may be by Month
for a whole year.

NB: To delete a query:


 Ensure that the query is not open in design or datasheet view
 Highlight it from the database window by clicking on it
 Press the ‘Delete’ key
 Confirm that you want to delete the query when prompted

Deleting a query has no effect on the data stored in the table(s) upon which it is based.

3.6 Creating Total Queries

Sometimes, you may want a query to summarize the information in a table without giving
details on each record.
For example, as a shopkeeper you may want to find out the total number of each product
you stock. You will need to create a query that groups this information accordingly and
calculates the required totals.

Procedure
Page 38 of 83
1. In the Database window, create a new query in Design View and add the table to be used
for the query.
2. Select the fields to appear in the query. Note that when creating a total query, you can
select the same field more than once as in the example below.

3. In the Query window, click the Totals button, or choose Totals from the View menu.

4. The Total row appears in the grid. The words ‘Group by’ appear under each field
selected in the Query.
5. When designing a total query, the fields to be used for grouping and the fields to be used
for totals (calculations) need to be specified.
 For fields to be used for Grouping, select ‘Group by’ in the Total Row.
Page 39 of 83
 For fields to be used for Totals, select a type of calculation e.g. Count, Sum or
Average from the drop-down list in the Total row. (See the table below for Types
of Totals possible)

TYPES OF TOTALS
Name Calculates:
Sum The total values in a field
Avg The average of values in a field
Count The number of values in a field
Max The highest value in a field.
StDev The std deviation of values in a field
Min The lowest value in a field
Var The variance of values in a field
First The field value from the first record in a table or query
Last The field value from the last record in a table or query.

6. Run the query to view the results.

7. As shown above, Microsoft Access displays headings that reflect the type of calculation
that has been performed to get the shown numbers e.g. CountOfSubject,
AvgOfUnitPrice, MaxOfSalary, CountOfNo etc.
Exercise
1. Create database Q1with the following tables and implement the accompanying conditions.
name owner species sex birth death
Fluffy Harold cat f 1993-02-04
Claws Gwen cat m 1994-03-17
Buffy Harold dog f 1989-05-13
Page 40 of 83
Fang Benny dog m 1990-08-27
Bowser Diane dog m 1989-08-31 1995-07-29
Chirpy Gwen bird f 1998-09-11
Whistler Gwen bird 1997-12-09
Slim Benny snake m 1996-04-29
a. The table should not allow a user to enter a date of birth that is earlier than the
year 1980
b. Sort the data by the field “birth” in ascending order
c. Create a query that will show us only the following species of animals:
dogs only
cats only
all the male dogs
all the female animals
all animals whose owner is Harold
all animals whose owner is Gwen
all animals whose owner is either Benny or Harold

Page 41 of 83
Lesson 4: Forms

FEATURES OF A FORM

1. CONTROL
These are elements that hold information in forms. A control has two parts: Label and control
field
E.g.
SURNAME MR. MUSAU

Control field (The


Label name is picked from
a table or a query)
2. UNBOUND CONTROLS

These are controls that are not linked to any table i.e. controls, which are not dragged, from a
table or a query.

4.01 creating forms using the form wizard

Ms Access has a form wizard which asks you questions about the form you want to create, then
creates a form based on your responses.

STEPS

1. In the Database window, click the Form button, and then choose the New button
2. In the Select A Table/Query box, type the name of the form’s source table or query, or select
one from the list.
3. Choose the Form Wizards button
4. Answer the questions in the Form Wizards dialog boxes. From the last dialog box, you can
display the form in Design view or Form view.

NOTE: If the Form Wizard doesn’t create the exact form you want, you can change the form
yourself in design view, or you can use the Form Wizard again and choose different option as you
answer the questions.

4.02 creating forms using auto form


1. In the database window, select the table or query for which you want to create a form.
2. Click the ‘New Object’ button and then select ‘Autoform’ from the dropdown list (AS
SHOWN).

Page 42 of 83
A new form is created based on the selected table or query. You can edit the controls in this
form just as if it was a form created without using the Autoform as explained below

4.03 creating a form using design view

While using a Form Wizard is the easiest way to create a form, it may not offer the design you
need. If you want to design a form yourself, create a blank form, and then add the controls and
other design features you require.

1. In the Database window, click the Form button, and then choose the New button. The new
form dialog box appears.
2. In the Select A Table/Query box, type the name of the form’s source table or query, or select
one from the list. (To create an Unbound form, leave this box empty).

3. Click ‘Ok’. A new blank form is shown as indicated below.

Page 43 of 83
4. Drag the fields that you would like to see in the form arrange and edit them as appropriate
using the properties window which is activated/deactivated by clicking on the icon as
shown.

Caption Box

5. To adjust the size of a control, click on it and use the fill handles to adjust it. This is done by
achieving the double headed arrow by positioning the mouse over any one of the ‘Fill
Handles’, clicking and holding the left mouse button then dragging inwards or outwards as
required.

Page 44 of 83
NB. You may also use the ‘Properties box’ to set other properties e.g. Change the colour display
by changing the entry in the ‘Fore Color’ text box.

Fill Handles

6. Save the form using an appropriate name

4.05 opening a data entry form

Once the form has been created, you may open it for data entry. You may do this by double
clicking on it in the database widow
OR
1. Click on the form to highlight it.
2. Click on the ‘Open’ button in the database window

Open button

4.06 customising a form

CREATING A CONTROL

As you design a form or a report, you place controls on it. The controls you create in design view
are the title, fields and pictures you see in form view.

1. From the menu bar select ‘View’ option, then ‘field list’ (in case it is not active)

Page 45 of 83
Field List

2. Drag the required fields from the list to the form, where they appear both the label and the
control field. By clicking inside the label, the user can delete and type a label of choice.

NB
All the fields can be dragged at once to the form by double clicking the headings of the field lists
and all the fields will be shaded blue. Point and drag them at once.

POSITIONING THE CONTROLS


Click to select the control to move, and then move the control by use of mouse pointers with the
following shapes:
 One finger: moves one part at a time
 Five fingers: moves both the label and the control field
Re-sizing can be done by pointing and dragging the dark spots.

DELETING A CONTROL
Click on the control to select it and then press the delete key

4.07 Object Linking and Embedding (Ole)

LINKING

When you link an OLE object, the object is stored in a separate file but it is displayed in your
form or report. Linking is used when one requires an OLE object to change when the data in the
source file changes

Page 46 of 83
EMBEDDING

When you embed an OLE object from another application, the object becomes part of your
database. When you want to edit the object, you open the application used to create it, make
changes to the embedded picture, and then return to your form window. The original file remains
unchanged.

EDITING OLE OBJECTS

After you embed an OLE object, you open the source application by double clicking the relevant
field in form view and then make changes.

Ole Object
4.08 Creating Unbound Controls

These are fields added to the form in design stage. A toolbox is activated from the “View” menu
which provides two useful icons for this purpose:

Aa This tool allows the entry of both the label and control fields.
Page 47 of 83
Ab| Allows entry of labels only e.g. When typing headings.

To create an Unbound control, you click the Ab| tool then mark the area to place the control by
dragging across the form. The label will bear a general name Text ... and the control unbound

4.09 Calculated Unbound Controls

This is a field added to the form created based on data of other fields dragged from a table/query.

1. Create an unbound control on the form


2. Select the unbound field and type an expression

E.g. To create a new field for Total Products Value:

CREATING A COMBO BOX

In many cases you will find it easier to choose an item from a list when editing or entering new
records into your table. A combo box helps to choose from such a list. The drop down list may be
extract from:
a) A Table/Query
b) A field list
c) A value list
Example

Page 48 of 83
Procedure

1. Create a table to contain the list of items to appear in the combo box. This Table is the Row
Source.
2. Select the table in which data from a Combo box will be inserted. In its design view, add a
new field to contain the data selected from a combo box. (In case it is missing). This field is
the Control Source.
3. Select the form based on the above-mentioned table, view it in Design State.
4. Disable the control wizard tool icon and then click the combo box button (Which turns grey
and suppressed).

Control Wizard

5. From the field list, drag the field added in two (2) above to the form.
6. Check its properties and on the option row source, type the name of the table that contains the
data for your combo box.
7. Save the form and open it to make your entries.

NOTE
To limit selection to only what is available in the combo box, set the property of Limit to list of
the combo box to Yes.

CREATING A LIST BOX


A list box is a variation of the combo box where the values are displayed in a list rather than a
dropdown list. Scroll bars are added to enable the use to choose any item from the list
Page 49 of 83
1. Create a table to contain the list of items to appear in the list box. This table is the Row
source.
2. Select the table in which data from a list box will be inserted. In its design view, add a new
field to contain the data selected from a list box. (In case it is missing). This field is the
Control Source.
3. Select the form based on the above mentioned table, view it in design state.
4. Disable the control wizard tool icon and then click the list box button (Which turns grey and
suppressed).
5. From the field list, drag the field added in two (2) above to the form.
6. Check its properties and on the option row source, type the name of the table that contains the
data for your list box.
7. Save the form and open it to make your entries.

NOTE
1. A list box shows a Up and Down arrow used for scrolling while searching for an entry. A
list box thus wastes space while a combo box opens up only when clicked.
2. Both the combo and list boxes can be used to display a different piece of data than what is
actually saved in the table
E.g.
You may be making use of CategoryIDs instead of CategoryNames when saving data in the
table as shown below (This will always be the case when your tables are properly
normalised)

Page 50 of 83
In the example above, Chai (The First Product) belongs to the Beverages category. On the
data entry form, if we wish to display the “Category Name” and not the “Category ID”
then we will in addition tio the steps listed above:

1) Invoke the Query Builder alongside the “CategoryID” Combo box.

2) Construct a query as shown below

Page 51 of 83
3) On closing answer “Yes” when prompted
4) Set the “Bound Column” property of the control as shown above to 2.
5) Save and open your table in datasheet view.

Page 52 of 83
4.09 Data Protection

From the Form properties, the user is able to control and maintain data security. One can set an
undelete form by indicating No to Allow deletions. This will ensure no values are deleted while
using the form. Forms can also be locked by setting Allow edits to NO and Record locks to All
Records. Once the form is locked, no changes can be made to a field.

CONCATENATION

This is the process of combining fields from a table into an Unbound control within a form. E.g. If
in a table we have two fields representing surname (SNAME) and first name (FNAME)
respectively and there is need to combine the two fields in the form so that the two names appear
together. An Unbound control tool will be used and the following formula used to concatenate the
fields.

FULLNAME =[SNAME]& “ “&[FNAME]


Label Concatenated
fields
4.10 Editing Data in a Form

FINDING RECORDS
It is possible to find records in a form just as it is in tables as explained in 1.6. To find records:
1. Open the form
2. Move to the field in which you want to search (e.g First Name.)
3. From the ‘Edit’ menu choose ‘Find’ then follow the instructions in 1.6

DELETING A DATA ENTRY FORM

To delete a data entry form:


1. Click on the form to highlight it
2. Press the ‘Delete’ key.
3. When promoted answer ‘YES’
NB: Even though forms are based on an underlying ‘Table’ or ‘Query’, deleting the form does not
have any effect on the data.

PRINT A DATASHEET
a) Open the form which contains the data that you would like to print
b) From the file menu choose “Print” To print all records, click ‘OK’
c) You may preview by choosing “Print Preview” i.e.

Page 53 of 83
FILTER BY FORM

To filter by form:
a) Open the form in ‘Datasheet’ View
b) From ‘Records’ choose ‘Filter’ then ‘Filter By Form’
c) Move to the field that you would like to filter by e.g. Category combo box appears to the
right, you may use this combo box to choose the data to filter OR you may type the data
directly
d) From ‘Records’ choose ‘Filter’ then ‘Apply Filter/Sort’. All filtered data will show in the
form
e) Remove the filter trough ‘Records’ ‘Filter’ then ‘Remove Filter/Sort’

Exercise
1. Create a table and a form based on the following data.

STAFF OVER-TIME PAY


NAME AMOUNT

Angeline Masumbuko 8500

Ajit Kumar 12500

Edward Kabarega 6500

2. Within the form, create a calculated Unbound control field to hold the tax deducted which is
10% of the amount paid.

Exercise

Page 54 of 83
NAME TOWN DEPARTMENT
James K Accra
Leila A Nairobi
Peter M. Mombasa

DEPARTMENT
Finance
Administration

Using the above data, create two tables. Following the instructions given earlier, create a combo
box to input department details to be part of the first table.

Page 55 of 83
Lesson 5: Reports

REPORTS
This is information that is organised and formatted to fit your own specifications e.g. mailing
labels, Invoices, Sell Summary and Phone lists.

1. Reports are an effective way for presenting information to be distributed in a printed


format. You can control the size and appearance of everything on a report, e.g. by
formatting the font style and size.
2. Pictures and graphs can be incorporated into the report to make the report more
meaningful.
3. Data can be organized and grouped into categories with sub-totals, making it easier to read.
For example, in a list of product sales, you can group records by products and get sub-
totals for each to see what product sold the most. In addition, calculations can be
performed on the data. For example, you can calculate totals for a field such as Total Sales.

5.01 creating using A Wizard


1. In the Database window, select the Reports tab.

2. The New Report dialog box appears. From the options in the “new report” dialog box,
select Report Wizard.

3. Choose the table that contains the data you want to base your report on and then click
OK.

Page 56 of 83
The table below describes what each option in the New Report dialog box does.

Option Description
Design View Used to create a report without
using a wizard.
Report Wizard Automatically creates a report
based on the fields selected.
AutoReport:Columnar Creates a single column report i.e.
the records are displayed in a
single column.
AutoReport : Tabular Creates a tabular report i.e. each
record is displayed from left to
right across a report (as a row of
fields).
Chart Wizard Creates a report with a chart.
Label Wizard Creates a report that has been
formatted for printing on mailing
labels.

Note: The Report Wizard contains a series of steps to be followed when creating a report.

4. Select the fields to appear on your report from the list of available fields. This allows
you to choose only the fields that you require in the report. Click on “Next”.

Page 57 of 83
5. Select the fields for grouping if required. Grouping data within a report means arranging the
data by a certain field so that all the records related to that field are displayed in one group. In
the example below, the data is to be grouped by the CategoryID field.

6. Select the fields to sort by and specify the sort order i.e. ascending or descending. You can sort
on up to four fields (levels) in the report.
Page 58 of 83
7. You may choose to summarise your report by adding other options by clicking on the
“Summary Options” button

8. Choose a layout for your report. You can also change the page orientation for the report to
landscape if you have many fields.

Page 59 of 83
9. Select the look or style you would like for the report. There are different looks to choose from
like corporate, formal or soft gray.

10. Type in the title for the report and then click on Finish.

Page 60 of 83
11. After a few seconds, the Report is generated in Print Preview.

Page 61 of 83
5.2 Creating Using Design View
Steps

1. From the Report Tab, click on New, then choose the table or query to be based on the report
then choose design view.
2. Drag the required fields from the field list into the Report details. If the field list is not visible,
active it by clicking on “View” then “Field List”. If you want the fields to be appearing on top
of each of the Pages, then drag the fields and drop them on the report Header.

NOTE
We can also use calculated or expressions in the reports

Examples

=now() : Will display the date and time


=(page) : Will number the pages
=[Field1]& “ “ &[Field2] :Will combine two fields.
=[Field]*0.1 :Will display a calculated field so long as the field is numeric.
To add these fields:
1. From the “Insert” menu choose the desired option as shown below

Page 62 of 83
Choose the desired style i.e.

Using Expressions in Reports


We can use expressions to perform arithmetic on fields, Sum a group of records and combine two
or more text fields.

Combining text fields


1. Create an Unbound control
2. Then inside the control type
=[Field1]& “ “&[Field2] e.g. =[FNAME]& “ “ &[SNAME]

Arithmetic
1. Create an Unbound control
2. Then inside the control type =[Field1]*[Field2] i.e. To calculate house allowance which is
15% of Salary we type =[Salary]*0.15

Summing a group of fields/Records

We use this information to add a group of fields i.e. If we want to sum together a group of fields
which are similar in difference records. For example, If we want to sum all “Units On Order” for
a particular supplier, we would include the expression “=Sum ([UnitsInStock])” in the “Supplier
Group footer”.

Page 63 of 83
To achieve this
1. Create Unbound control on the report footer or group footer
2. Type =sum([UnitsInStock])

Results

5.03 Sections of the Report

Report Header.
This section has the main header or title for the report. It is printed once at the beginning of
the report.

Page Header
This section contains information to be printed at the top of each page of the report. This may
include information like date or column titles.

Group header
This section contains information that is printed at the beginning of each record in the table.
This section is present only when there is grouped data in the report. The name given to this
section depends on the grouping field. In the example above, the report is grouped on Subject
and hence the name ‘Subject Header’.

Detail
This section contains information that is printed for each record in the table i.e. the main area
of the report that contains the actual records.

Page 64 of 83
Group Footer
Similar to group header but this section contains information that is to be printed at the end of
each grouping of data. A good example of this is sub-totals.

Page Footer
This section contains information that is to be printed at the bottom of each page e.g. page
totals, page numbers etc.

Report Footer
Just like the report header, this section contains information that is printed once at the end of
the report like Grand Totals etc.

5.04 Previewing and printing your report


This is important when:
1. You want to see or view how the report will look like when it is printed.
2. Whenever you need a paper copy of the report to present to other people and for filing.

Double click on the report that you would like to view OR choose the “preview” option in the
database window.

To preview two Pages

Suppose you want to view only two pages of the report, click on the two pages Button on the
toolbars.

Two
Pages

To view more than two pages, then:

1. From the ‘View’ menu choose the option ‘Pages.’


2. Select the number of pages you want to display
Page 65 of 83
To Exit from Print Preview.

Click on the Close button.


When you exit from Print Preview, you can view the report in Design View.

Page 66 of 83
Creating Reports from Queries
If you require information is needed from many tables, the best method is to create a query
that incorporates all the required tables and then create a report from the query.

Procedure
1. In the Database Window, select the Reports Tab and click on New.
2. Select the query to be used for the report.
3. Select the fields you want to use from the query.

4. Complete the remaining steps in Report Wizard and preview the report.

Page 67 of 83
3.

5.05 Reports Based In Multiple Tables.

When you want to obtain information from more than one table for example you
may want to know who works in which department, which floor and when they were
employed. This cannot be obtained from the tables independently hence we need both
to provide this information.

Page 68 of 83
Procedure
1. Create relationships between the tables as appropriate.
2. From the database window choose ‘Reports’ and then click on ‘New’. Choose
the ‘Report Wizard’ option. Choose a table on which to base your report then
Click ‘OK’.

3. In the next step choose tables and then the fields from those tables that are
required.

8. Determine how the information is going to be grouped then Click on Next to proceed.
9. Complete the remaining steps and preview the report.

Page 69 of 83
10. To change orientation
 Open the report in either design or datasheet view
 From the ‘file’ menu, choose ‘Page setup’
 The following dialog appears

 Switch between portrait and landscape as desired.

Page 70 of 83
5.6 To print the report
 From the ‘file’ menu choose print
 To print using default settings click on ‘OK’ else change the settings then print

Exercise

1. Create the following table and save it using a suitable name.


2. Then create a report based on the table.
3. Let the report have the following:-
 Grand Totals for all the persons
 Sub Total for the Department
 Date and time, and Page Number on the Page footer
4. Let also the report have the Full Names on one control.
5. Save the report under a good name
6. From the same table, create a parameter query and save it.
7. Create a separate report based on this parameter query.
8. Create an Unbound control for Tax which is 15% of Salary.

FNAME SNAME DEPARTMENT SEX SALARY

Jones Thomas Computer Male 4000.00


Jane Ken Production Female 5000.00
Loise Denis Sales Female 4500.00
David Walter Computer Male 6200.00
Charles Challa Sales Male 8900.00
George Michael Computer Male 6000.00
Titus Emma Production Female 6400.00
Ester Tonny Sales Female 4200.00

Page 71 of 83
Ms Access Project
Table: Categories
Columns
Name Type Size
CategoryID Long Integer 4
CategoryName Text 15
Description Memo -
Picture OLE Object -

Relationships

CategoriesProducts
Categories Products
CategoryID

Attributes: Enforced
RelationshipType: One-To-Many

Table: Customers
Columns
Name Type Size
CustomerID Text 5
CompanyName Text 40
ContactName Text 30
ContactTitle Text 30
Address Text 60
City Text 15
Region Text 15
PostalCode Text 10
Country Text 15
Phone Text 24
Fax Text 24

Relationships

CustomersOrders
Customers Orders
CustomerID 1  CustomerID
Attributes: Enforced, Cascade Updates
RelationshipType: One-To-Many

Page 72 of 83
Table: Employees
Columns
Name Type Size
EmployeeID Long Integer 4
LastName Text 20
FirstName Text 10
Title Text 30
TitleOfCourtesy Text 25
BirthDate Date/Time 8
HireDate Date/Time 8
Address Text 60
City Text 15
Region Text 15
PostalCode Text 10
Country Text 15
HomePhone Text 24
Extension Text 4
Photo OLE Object -
Notes Memo -
ReportsTo Long Integer 4

Relationships

EmployeesOrders
Employees Orders
EmployeeID 1  EmployeeID

Attributes: Enforced
RelationshipType: One-To-Many

Table: Order Details


Columns
Name Type Size
OrderID Long Integer 4
ProductID Long Integer 4
UnitPrice Currency 8
Quantity Integer 2
Discount Single 4

Page 73 of 83
Relationships

OrdersOrder Details
Orders Order Details
OrderID 1  OrderID

Attributes: Enforced, Cascade Deletes


RelationshipType: One-To-Many

ProductsOrder Details
Products Order Details
ProductID 1  ProductID

Attributes: Enforced
RelationshipType: One-To-Many

Table: Orders
Columns
Name Type Size
OrderID Long Integer 4
CustomerID Text 5
EmployeeID Long Integer 4
OrderDate Date/Time 8
RequiredDate Date/Time 8
ShippedDate Date/Time 8
ShipVia Long Integer 4
Freight Currency 8
ShipName Text 40
ShipAddress Text 60
ShipCity Text 15
ShipRegion Text 15
ShipPostalCode Text 10
ShipCountry Text 15

Page 74 of 83
Relationships

CustomersOrders
Customers Orders
CustomerID 1 CustomerID

Attributes: Enforced, Cascade Updates


RelationshipType: One-To-Many

EmployeesOrders
Employees Orders
EmployeeID 1  EmployeeID

Attributes: Enforced
RelationshipType: One-To-Many

OrdersOrder Details
Orders Order Details
OrderID 1  OrderID

Attributes: Enforced, Cascade Deletes


RelationshipType: One-To-Many

ShippersOrders
Shippers Orders
ShipperID 1  ShipVia

Attributes: Enforced
RelationshipType: One-To-Many

Page 75 of 83
Table: Products
Columns
Name Type Size
ProductID Long Integer 4
ProductName Text 40
SupplierID Long Integer 4
CategoryID Long Integer 4
QuantityPerUnit Text 20
UnitPrice Currency 8
UnitsInStock Integer 2
UnitsOnOrder Integer 2
ReorderLevel Integer 2
Discontinued Yes/No 1

Relationships

CategoriesProducts
Categories Products
CategoryID 1  CategoryID

Attributes: Enforced
RelationshipType: One-To-Many

ProductsOrder Details
Products Order Details
ProductID 1  ProductID

Attributes: Enforced
RelationshipType: One-To-Many

SuppliersProducts
Suppliers Products
SupplierID 1  SupplierID

Attributes: Enforced
RelationshipType: One-To-Many

Page 76 of 83
Table: Shippers
Columns
Name Type Size
ShipperID Long Integer 4
CompanyName Text 40
Phone Text 24

Relationships

ShippersOrders
Shippers Orders
ShipperID 1  ShipVia

Attributes: Enforced
RelationshipType: One-To-Many

Table: Suppliers
Columns
Name Type Size
SupplierID Long Integer 4
CompanyName Text 40
ContactName Text 30
ContactTitle Text 30
Address Text 60
City Text 15
Region Text 15
PostalCode Text 10
Country Text 15
Phone Text 24
Fax Text 24

Relationships

SuppliersProducts
Suppliers Products
SupplierID 1  SupplierID

Attributes: Enforced
RelationshipType: One-To-Many
Page 77 of 83
Tasks
6.1 Tables
1) Create ALL the tables as listed above. DO NOT create the relationships until you are done with constructing the
tables.
2) Create the relationships between the tables as specified above.
3) Enter data in the tables. Ensure that you follow the order: Categories, Shippers, Employees, Customers, Suppliers,
Products, Orders and Order Details.

Categories

ID Category Name Description Picture


1 Beverages Soft drinks, coffees, teas, beers, and ales
2 Condiments Sweet and savory sauces, relishes, spreads, and
seasonings
3 Confections Desserts, candies, and sweet breads
4 Dairy Products Cheeses
5 Grains/Cereals Breads, crackers, pasta, and cereal
6 Meat/Poultry Prepared meats
7 Produce Dried fruit and bean curd
8 Seafood Seaweed and fish

Page 78 of 83
Employees
ID Last Name First Title Title Birth Date Hire Date Address City Region Postal Country Home Ext. Notes Repo
Name Code Phone rts To
1 Davolio Nancy Sales Ms. 08-Dec-48 01-May-92 507 - 20th Ave. E. Seattle WA 98122 USA (206) 555- 5467 Education includes a BA in 2
Representative Apt. 2A 9857 psychology
2 Fuller Andrew Vice President, Dr. 19-Feb-52 14-Aug-92 908 W. Capital Tacoma WA 98401 USA (206) 555- 3457 Andrew received his BTS
Sales Way 9482 commercial in 1974
3 Leverling Janet Sales Ms. 30-Aug-63 01-Apr-92 722 Moss Bay Kirkland WA 98033 USA (206) 555- 3355 Janet has a BS degree in 2
Representative Blvd. 3412 chemistry
4 Peacock Margare Sales Mrs. 19-Sep-37 03-May-93 4110 Old Redmond WA 98052 USA (206) 555- 5176 Margaret holds a BA in English 2
t Representative Redmond Rd. 8122 literature
5 Buchanan Steven Sales Manager Mr. 04-Mar-55 17-Oct-93 14 Garrett Hill London SW1 8JR UK (71) 555- 3453 Steven Buchanan graduated from 2
4848 St. Andrews University
6 Suyama Michael Sales Mr. 02-Jul-63 17-Oct-93 Coventry House London EC2 7JR UK (71) 555- 428 Michael is a graduate of Sussex 5
Representative Miner Rd. 7773 University
7 King Robert Sales Mr. 29-May-60 02-Jan-94 Edgeham Hollow London RG1 9SP UK (71) 555- 465 Robert King served in the Peace 5
Representative Winchester Way 5598 Corps
8 Callahan Laura Inside Sales Ms. 09-Jan-58 05-Mar-94 4726 - 11th Ave. Seattle WA 98105 USA (206) 555- 2344 Laura received a BA in 2
Coordinator N.E. 1189 psychology
9 Dodsworth Anne Sales Ms. 27-Jan-66 15-Nov-94 7 Houndstooth London WG2 7LT UK (71) 555- 452 Anne has a BA degree in English 5
Representative Rd. 4444

Suppliers
ID Company Name Contact Name Contact Title Address City Region Postal Code Country Phone
1 Exotic Liquids Charlotte Cooper Purchasing Manager 49 Gilbert St. London EC1 4SD UK (171) 555-2222
2 New Orleans Cajun Shelley Burke Order Administrator P.O. Box 78934 New LA 70117 USA (100) 555-4822
Delights Orleans
3 Grandma Kelly's Regina Murphy Sales Representative 707 Oxford Rd. Ann Arbor MI 48104 USA (313) 555-5735
Homestead
4 Tokyo Traders Yoshi Nagase Marketing Manager 9-8 Sekimai Tokyo 100 Japan (03) 3555-5011
Musashino-shi
5 Cooperativa de Quesos Antonio del Valle Export Administrator Calle del Rosal 4 Oviedo Asturias 33007 Spain (98) 598 76 54
'Las Cabras'
6 Mayumi's Mayumi Ohno Marketing 92 Setsuko Osaka 545 Japan (06) 431-7877
Representative Chuo-ku
7 Pavlova, Ltd. Ian Devling Marketing Manager 74 Rose St. Melbourne Victoria 3058 Australia (03) 444-2343
Moonie Ponds
8 Specialty Biscuits, Ltd. Peter Wilson Sales Representative 29 King's Way Manchester M14 GSD UK (161) 555-4448
9 PB Knäckebröd AB Lars Peterson Sales Agent Kaloadagatan 13 Göteborg S-345 67 Sweden 031-987 65 43
10 Refrescos Americanas Carlos Diaz Marketing Manager Av. das Americanas 12.890 São Paulo 5442 Brazil (11) 555 4640
LTDA

Customers
Custome Company Name Contact Name Contact Title Address City Region Postal Country Phone Fax
r ID Code

Page 79 of 83
ALFKI Alfreds Futterkiste Maria Anders Sales Obere Str. 57 Berlin 12209 German 030-0074321 030-0076545
Representative y
ANATR Ana Trujillo Emparedados Ana Trujillo Owner Avda. de la México D.F. 05021 Mexico (5) 555-4729 (5) 555-3745
y helados Constitución 2222
ANTON Antonio Moreno Taquería Antonio Moreno Owner Mataderos 2312 México D.F. 05023 Mexico (5) 555-3932
AROUT Around the Horn Thomas Hardy Sales 120 Hanover Sq. London WA1 UK (171) 555-7788 (171) 555-6750
Representative 1DP
BERGS Berglunds snabbköp Christina Berglund Order Administrator Berguvsvägen 8 Luleå S-958 Sweden 0921-12 34 65 0921-12 34 67
22
BLAUS Blauer See Delikatessen Hanna Moos Sales Forsterstr. 57 Mannheim 68306 German 0621-08460 0621-08924
Representative y
BLONP Blondel père et fils Frédérique Citeaux Marketing Manager 24, place Kléber Strasbourg 67000 France 88.60.15.31 88.60.15.32
BOLID Bólido Comidas Martín Sommer Owner C/ Araquil, 67 Madrid 28023 Spain (91) 555 22 82 (91) 555 91 99
preparadas
BONAP Bon app' Laurence Lebihan Owner 12, rue des Bouchers Marseille 13008 France 91.24.45.40 91.24.45.41
BOTTM Bottom-Dollar Markets Elizabeth Lincoln Accounting 23 Tsawassen Blvd. Tsawassen BC T2F Canada (604) 555-4729 (604) 555-3745
Manager 8M4
Products

ID Product Name Supplier Category Quantity Per Unit Unit Units In Units On Reorder Discontinued
Price Stock Order Level
1 Chai 1 1 10 boxes x 20 $18.00 39 0 10 No
bags
2 Chang 1 1 24 - 12 oz bottles $19.00 17 40 25 No
3 Aniseed Syrup 1 2 12 - 550 ml $10.00 13 70 25 No
bottles
4 Chef Anton's Cajun 2 2 48 - 6 oz jars $22.00 53 0 0 No
Seasoning
5 Chef Anton's Gumbo 2 2 36 boxes $21.35 0 0 0 Yes
Mix
6 Grandma's 3 2 12 - 8 oz jars $25.00 120 0 25 No
Boysenberry Spread
7 Uncle Bob's Organic 3 7 12 - 1 lb pkgs. $30.00 15 0 10 No
Dried Pears
8 Northwoods Cranberry 3 2 12 - 12 oz jars $40.00 6 0 0 No
Sauce
9 Mishi Kobe Niku 4 6 18 - 500 g pkgs. $97.00 29 0 0 Yes
10 Ikura 4 8 12 - 200 ml jars $31.00 31 0 0 No

Page 80 of 83
Orders

Order Customer Empl Order Required Shipped Ship Freight Ship Name Ship Address Ship City Ship Ship Ship
ID oyee Date Date Date Via Region Postal Country
Code
10265 BLONP 2 25-Aug-94 22-Sep-94 12-Sep-94 1 Ksh 55.28 Blondel père et 24, place Klébe Strasbourg 67000 France
10278 BERGS 8 12-Sep-94 10-Oct-94 16-Sep-94 2 Ksh 92.69 Berglunds Berguvsvägen 8 Luleå S-958 22 Sweden
snabb
10280 BERGS 2 14-Sep-94 12-Oct-94 13-Oct-94 1 Ksh 8.98 Berglunds Berguvsvägen 8 Luleå S-958 22 Sweden
snabb
10297 BLONP 5 05-Oct-94 16-Nov-94 11-Oct-94 2 Ksh 5.74 Blondel père et 24, place Klébe Strasbourg 67000 France
10308 ANATR 7 19-Oct-94 16-Nov-94 25-Oct-94 3 Ksh 1.61 Ana Trujillo Em Avda. de la Con México D.F. 05021 Mexico
10326 BOLID 4 10-Nov-94 08-Dec-94 14-Nov-94 2 Ksh 77.92 Bólido Comidas C/ Araquil, 67 Madrid 28023 Spain
10331 BONAP 9 16-Nov-94 28-Dec-94 21-Nov-94 1 Ksh 10.19 Bon app' 12, rue des Bou Marseille 13008 France
10340 BONAP 1 29-Nov-94 27-Dec-94 09-Dec-94 3 Ksh 166.31 Bon app' 12, rue des Bou Marseille 13008 France
10355 AROUT 6 16-Dec-94 13-Jan-95 21-Dec-94 1 Ksh 41.95 Around the Brook Farm Colchester Essex CO7 6JX UK
Horn Str

Order Details

Order ID Product Unit Price Quantity Discount


10265 1 $5,000.00 4 0%
10265 4 $4,000.00 3 0%
10278 6 $5,900.00 3 0%
10278 10 $5,600.00 5 0%
10280 7 $3,400.00 3 0%
10280 9 $5,000.00 2 0%
10297 4 $3,400.00 1 0%
10297 5 $7,800 .00 1 0%
10308 5 $7,000.00 4 0%
10308 6 $5,600.00 4 0%
10326 4 $17.60 24 0%
10326 8 $4,500.00 1 0%
10331 8 $2,200.00 2 0%
10331 9 $5,600.00 12 0%
10340 4 $5,000.00 1 0%

Page 81 of 83
6.2 Queries

1) Construct queries to accomplish the following tasks


a. From the Categories and products table show the following
fields
CategoryName, ProductName, Price – In a new field,
compute the total value of each product i.e. UnitsInStock *
UnitPrice
b. Create a new field in the Products Table called “TotalValue” then
make an Update query to update this field with the total value
as described above.
c. Select all products with the letter “P” anywhere in the Name.
d. We would like to know the value of all products within a
category (e.g. the value of all products uinder the category
‘Condiments’). Construct a query to group the products and sum
up the total values. HINT use the concept in a) above

6.3 Forms

1) Using autoform, construct forms for all tables apart from the
categories and products tables
2) Using the design view construct forms for the categories and products
tables.
3) Add a new control (UNBOUND) to display the total value of each
product on the form
4) Add 1 product of your choice in the products table using the Products
Form.
5) Delete the Categories Form
6) Using ‘filter By Form’, filter for all products of Type ‘Condiments’
7) Using ‘Find’ search for ‘Aniseed Syrup’.

6.4 Reports
1) Construct a report based on the Query in 6.2 1(a) grouping the data
by ‘CategoryName’ using the report wizard
2) Modify the report above by:
a. Changing the colour of all labels to a different colour.
b. Adding a field to show a count of the records in each category
i.e. (number the records)
c. Adding a field to show the total value of the product under each
category.

Page 83 of 83

S-ar putea să vă placă și