Vous êtes sur la page 1sur 38

Using Microsoft Office Access

With External DBMSes

The purpose of this tutorial is to give you some basic
familiarity with using Microsoft Office Access to access
external DBMSs, as a client-side database application
development tool.

It is strongly recommended that you read through all the

slides before you begin following the instructions.

NOTE: Due to security restrictions on external access to

university facilities, this exercise must be done in the
specialist labs on the lab computers. It will not work over
wifi, outside the specialist labs, or outside the campus.
Microsoft Office Access
Microsoft Office Access is a component of Microsofts
flagship Office productivity suite.

It is:
A stand-alone DBMS of very limited multi-user capability
A general-purpose database administration and editing utility
A general-purpose 4th generation database application tool.

For the latter two items, it can connect to any ODBC-

capable DBMS.

It is especially popular for developing corporate

applications, prototypes, and bespoke software.
Tutorial Prerequisites
This tutorial will use your MySQL database from last

If you successfully completed last weeks porting exercise,

youve got everything you need. Go to the next slide.

If you havent successfully completed last weeks porting

exercise, you must complete it first! Come back here when
youre done.
Step 1 Starting Access
Open Access via:
All Programs | Microsoft Office 2013 | Access 2013

You should see a screen like that on the following

Step 2 New Database Project

Click the Blank desktop database icon

toward the top of the window. That will
allow you to:
Create a new database using Accesss built-in
DBMS, or
Start a new database project to access an
external DBMS such as MySQL.

You should see a screen like that on the

following slide
Step 2 (continued)

In the File Name blank, you may choose

a new file name if you wish.

Press the Create button to create the

database file.
Step 3 Connect to a DBMS

Select the External data tab at the top of

the window.

Choose ODBC Database from the

More item.
Step 3 (continued)

You should now see a dialog box like that

on the following slide
Step 3 (continued)

Choose the Link to the data source by

creating a linked table option.

You should see a dialogue box as

described on the following slide.
It is a standard Windows ODBC dialog box; a
similar one will appear in any database
product that supports ODBC under Windows.
Step 3 (continued)
1. Click the Machine Data Source tab.

2. Click the New button. The system will warn you that You are
logged on with non-Administrative privileges. Click Ok.

3. A Create New Data Source dialogue box will appear. Click Next.

4. Choose MySQL ODBC 5.2 Unicode Driver from the list, then
press Next.

5. Click Finish. You should see a dialogue box like that on the next
Step 3 (continued)
Fill it in as follows, then press OK:

Data Source Name:


My MySQL Database

TCP/IP Server:

<your MySQL account name>

<your MySQL password>

<your MySQL database name>
Note: Same as User
You should see a dialogue box like the following:

Click on the connection you just created

(MyMySQLDatabase) and press Ok.

You should see a dialogue box like that in the following

1. Highlight the DEPT and EMP tables as shown.

2. Check the Save password checkbox.

3. Press OK.

You should see a screen like that on the following slide.

Step 4 MySQL Tables in Access

Double-Click on the DEPT and EMP

tables on the left.

You should see something like that on the

following slide
Step 4 MySQL Tables in Access

Try editing data in the tabular display.

Whilst youre editing, Microsoft Access is

translating your actions into SQL queries.
When you insert data, it becomes an INSERT
When you change data, it becomes an
UPDATE query, etc.
Step 5 Creating Forms
Unfortunately, a tabular display of data is not to
everyones liking. Forms can be created to
make the data easier to edit for non-database

Select Create from the tabs at the top of the

window, then select Form to create a form.

It will look something like that on the following

slide (Note: my table names might be different from yours.)
Step 5 Creating Forms

You can use the View options on the

upper left to switch between design view,
which lets you design the form, and edit
view, which lets you use the form to edit

When youre happy with the form, you

should save it, as follows
Step 5 Creating Forms

You should now create a form for the EMP


It will look something like that on the

following slide
Step 6 Drop-Down Comboboxes Help Select
Foreign Key Values

The DEPTNO field is a foreign key that references the

DEPTNO column in the DEPT table.

Try adding a new row to the EMP table.

Finding an appropriate DEPTNO is awkward you have

to use a number that exists in the DEPT table.

Wouldnt it be better if we could use Access to help us

find it?
Step 6 Drop-Down Comboboxes Help Select
Foreign Key Values

We can create a drop-down combobox to

help automate selection of the appropriate
foreign key value:

Switch to the Design view on the EMP form.

Right click on the DEPTNO field.
Select Change to and pick Combo Box.
You can use the following slide to help you
find it
Step 6 Drop-Down Comboboxes Help Select
Foreign Key Values

See the property sheet on the right. Find

the Row Source property.

Put the following SQL query in it:

select * from dept order by deptno

Use the following slide to help you

Step 6 Drop-Down Comboboxes Help Select
Foreign Key Values

Now switch to the edit view

Note how you can use the drop down combobox

to select foreign key values. Whenever you drop
down the list, the query you specified on the
previous slide is executed, and the results used
to populate the list.

It should look something like the following

Step 7 - Practice
1. Now try linking the ORD and CUSTOMER tables from
your MySQL database.

2. Create forms for the ORD and CUSTOMER tables.

3. Create a drop down combobox on the ORD form to

select CUSTID values from the CUSTOMER table.
This will help users to fill in the CUSTID field on the
ORD form.

4. Try using the property sheets on your forms to give the

field prompts more meaningful names.
NOTE: Dont Make a Common Mistake

In Microsoft Access forms, drop-down comboboxes are

intended for selecting foreign key values.

They are not intended for creating search or find

facilities. Find is built-in and invoked via Ctrl-f.

There is no reason to use drop-down comboboxes as a

general-purpose search or find facility in Microsoft
For Your Portfolio
1. In addition to the EMP, DEPT, ORD and CUSTOMER forms youve just created, link and create forms for
the BONUS, ITEM, PRICE, PRODUCT and SALGRADE tables. SALES is a view and doesnt need a form.

2. Make sure all foreign key values in all forms can be selected via drop-down comboboxes. Do not put a
combobox on every field! That would be pointless (and annoying to the user). Comboboxes should only
be used to select from a restricted set of available values typically foreign key values.

3. Change all field prompts and form titles to be human-friendly. (E.g., EMP is a rather unfriendly form title;
Employees is a good title. HIREDATE is a poor prompt but Date hired is a good one, etc.)

4. Make sure all field sizes are appropriate to the data types they contain. On automatically-generated forms,
all fields will be the same size. Should a field holding a date be just as long as a field that holds an
employee name?

5. Link to the SALES view and create a report to present SALES in a human-friendly fashion. For extra
marks, create a form and appropriate query (or queries) to allow the user to produce a SALES report for
either a user-specified product ID or for all product IDs.

6. Create a menu (or switchboard) to open your forms and show the Sales report by clicking appropriate and
clearly-labelled buttons.

7. Put the completed Access file (e.g., Week7.accdb) in your portfolio in folder called