Sei sulla pagina 1di 11

BA937 Access Tutorial

The Student Enrolment System


Objective: This tutorial provides a step-by-step guide to creating a simple enrolment
database with a form that updates the database. By doing this tutorial you will
improve your skills with Microsoft Access and your understanding of relational
database.

Note: So that you can give this tutorial your undivided attention, it is recommended
you close all the processes shown in the task bar at the bottom of your screen before
you start this tutorial.

Microsoft Office Access 2003.lnk


1). Start Access by clicking on the Access icon (on the start menu or in the programs
section) and Create a Blank Database called ABC College. Access will create a file
called ABC College.mdb and you will now see the screen below:

Fig 1

ABC College offers a variety of graduate and postgraduate accounting subjects as


follows:

Fig 2

© Pat Thompson Page 1 of 11


We need to design a table to store these course details. In Access, select the table
object and Create table in Design view. Below is a suggested layout for the table:

Fig 3

2). Create and save the design of the table. Limit the size of the course code to 5
characters. The Course_Code uniquely defines the course, so it is the logical primary
key.

Notice that we have replaced the course level (graduate or postgraduate) with
Level_Code, a number. If we use 0 for graduate and 1 for postgraduate it will save
space in our table.

Fig 4

We now need a table that shows the relationship between the Course_Level and the
Level_Code we have invented.

3). Design a Course Level table and enter the data shown below:

Fig 5

A table is now required to store details of the students who have enrolled at ABC
College. The table design below details the information required.

Fig 6

4). Use this Students table to enter the details of the enrolled students which are
shown on the next page. Notice that we have used Level_Code to indicate which
students are studying for a graduate degree and those who are post-graduate.

© Pat Thompson Page 2 of 11


Fig 7

Now we need to enrol students in subjects. For each enrolling student we need to
capture the year, the teaching period (TP1, TP2 or TP3), whether they are paying by
cash or by credit and the date they enrol. Then we need to record each subject they
enrol in. To enrol, students fill out the form below:

Fig 8

To transform the data on this form into a relational database we need to observe that
there is one form heading (from name through to date) and a number of subjects. In
database language, it is a 1 to many relationship. We need to create one table for the
form heading, and another table for the subjects. Importantly, we must have a
relationship so that the subjects enrolled table can be associated with the student.

© Pat Thompson Page 3 of 11


When a student enrols, they are given a unique enrolment number (similar to a receipt
number) which is written on their enrolment form. Access has a facility to generate
this number, using a datatype called ‘Autonumber’. As this number uniquely
identifies the enrolment form, it is an ideal primary key for the table that stores the
form heading data which could be documented as follows:

Fig 9

Enrolment_Number will also be stored in the table which records the subjects the
student has enrolled in, to be the foreign key that provides the link back to the correct
record in the enrolment heading table. Our Enrolled Subjects table will only need two
fields, the Enrolment_Number and the Subject. In design view it will be:

Fig 10

The important issue to note here is that Enrolment_Number is datatype number not
auto-number. The Enrolment Subjects table will pick up Enrolment_Number from the
Enrolment Heading table. If it were made an autonumber the child record would have
a different Enrolment_Number to the parent record (in the Enrolment Header table)
and we would have no way of linking subjects back to students.

Forms

It is far too complicated to type enrolment information directly into our two new
tables. By using a form we can make it a fairly simple task. What we need is a form
that is very similar to the ABC College Enrolment Form.

Create the form in two parts, as the top of the form is columnar (one student per form)
and the lower part of the form is tabular (many subjects per student).

5). To create the top of the form select the Forms object and:


• Select the
• Select all fields in this table, so that the form can update the table
• Choose format
• Put your name on the form, eg

Your finished screen will look something like:

© Pat Thompson Page 4 of 11


Fig 11

6). Go into Design view and make the following five changes to your enrolment form:

1. Move all the Data Items from Student_ID onward down, so that there is space
for another field.
2. In the space you have just made, place a combo box that shows the students
Family Name and Given Name. Ensure you answer the combo box wizard
so that the Student_ID
corresponding to the name you have selected updates the Enrolment Heading
table
3. Make the Teaching_Period a combo box that displays a list, TP1, TP2 and
TP3. (Refer Note 2 below)
4. Make the Cash_or_Credit a combo box with Cash or Credit.
5. Take the underscores out of the text to make your form more professional.

Note1: By right clicking the mouse on a text box or combo box you can set default
values (for example 2006 for the year, or TP3 for the Teaching Period) and you can
set validation rules, for example for Teaching Period you could specify = TP1 or TP2
or TP3.

Note 2: Where you need select from a small list of items (such as TP1, TP2 and TP3,
you can use the Combo Box wizard to type them in as shown below

Fig 12

and in the following dialog box type in the list as shown on the following page

© Pat Thompson Page 5 of 11


Fig 13

Once you have done this, your form should look something like:

Fig 13

7). Select the ‘Create Form using Wizard option to create the Enrolment Subject form
as follows:

Fig 13

Making sure you select format to get the repeating rows on your
form to allow enrolment in more than one subject. Leave the background the same as
your header form (otherwise your form will look blah). The name of the form doesn’t
matter as we will delete it shortly.

© Pat Thompson Page 6 of 11


The completed form will look something like:

Fig 14

The detail form (Enrolment Subjects) we have just made needs to be placed on the
main form.

8). Close all tables and forms. Open your heading form (in this example it is called
Pats Enrolment Form) in design view. As shown below:
• enlarge it;
• move the form footer down;
• move the Access menu pane to the top left of your desktop and the form
toward the bottom right.

Fig 15

9). Place the mouse pointer on the Enrolment subjects screen, depress the left mouse
key and keep it depressed as you drag it onto the main form (in this case Pat’s
Enrolment Form). Place it below ‘Enrolment Date’ and release the mouse key.

© Pat Thompson Page 7 of 11


Fig 16

The form is not finished, however it is helpful to use it at this stage:

• to understand how the child form (Enrolment Subjects) picks up the


enrolment number from the parent form (Pat’s Enrolment Form);
• The data that is stored in the Enrolment Header table from this
transaction

• The data that is stored in the Enrolment Subjects table

Fig 17

The key point to understand is that the Enrolment Number is the link between the
tables. It defines the relationship.

9). Close all forms and tables. Open the Enrolment Subjects table in design mode.
Delete both text boxes, and one of the headings. The form should now look like:

© Pat Thompson Page 8 of 11


Fig 18

We will now place a combo box (just below the ‘Detail’ line) and link it to the
subjects in the Subjects Table as follows:

• then select

• Have your combo box display the course titles

• And then translate this name back to the course code to update the
enrolment subjects table

Note 3: The Enrolment Number which was deleted from the form is still associated
with the form, even though it is not displayed. The number will pass through the form
and update the database even though the user will not see it.

The form should now look something like:

Fig 18

Delete ‘Course_Title’, expand the ‘Subject_Code combo box, and update the heading.

© Pat Thompson Page 9 of 11


The child form will now look like:

Fig 19

Note 4: If your form has multiple lines and shows some data there is no problem, the
form is simply picking up the data from the related table.

10). Delete all records from the Enrolment Heading and Enrolment subjects tables.

11). Open your main form. It should look like:

© Pat Thompson Page 10 of 11


12). Use the form to enrol the students for TP3 as follows:

13). List the contents of the Enrolment Header and Enrolment Subjects tables and
trace through the Enrolment_Number relationship that links them.

14). Write the following queries:


1. List the Postgraduate subjects being done by students from India.
2. How many subjects are being done by Indian students, Pakistani
students and Chinese students.

© Pat Thompson Page 11 of 11

Potrebbero piacerti anche