MS Access Part I
MS Access Part I
(Part-I)
Faculty of Engineering
University of Ruhuna
June 2020 Dr. J.M. Ruwan S. Appuhamy
Introduction
What is MS Access
Access is an electronic relational database application that helps to manage
large amounts of information.
What is a Database
A variety of definitions exist for a database; but
essentially it's a collection of information. A filing
cabinet, a Rolodex, a library card catalog, and even
the Internet are all types of databases.
Most often the word "database" is used to describe a collection of related
"data" (information) stored on computers.
Access provides a mechanism for storing, organizing, accessing,
manipulating and reporting on large quantities of data.
You can create simple databases by creating a Word Table or an Excel
spreadsheet. These can be used to keep data such as names and addresses.
Introduction
Why do we use Microsoft Access?
Microsoft Access is a "relational" database application. Relational means
we can link together sets of data, we can relate the data.
For ex: we can keep track of the patients, the
doctors and when the patients last saw their
doctors, what happened at each visit and so on.
Access allows us to relate our data, without the
repetition that may occur anywhere else.
An electronic database works much the same
way as a manual filing system, except that all
of the information is stored electronically.
Information in a filing system is usually
organized in some logical manner, such as
alphabetically by last name, by product
category, by geographic region, etc.
Information in Microsoft Access is also
organized in a logical manner using TABLES.
Introduction
What it a Database Table?
The database table is the basic unit of storage in Access. Each database will
contain many different tables, and relationships will exist between tables.
For ex; an employee database contains information about each employee of
their company, such as:
Employee ID Street Address Zip Code
Name City Home Phone
Date of Hire State Gender etc.
The Getting Started with Microsoft Office Access screen will appear as below.
Creating an Access 2007 Database
We’ll begin with a Blank Database and increase our database knowledge with
each step.
Look at the center of your Access screen. You will see –
Getting Started with Microsoft Office Access. Below the
title you will see a Blank Database button.
Click the Blank Database button.
To Save,
File name
(better with no spaces)
Click OK
Ribbon
Groups
When we clicked the Create button Access assumed we desired to create – within
our Employee database – another database – which is called a Table. You’ll
notice that at the top of the above image that the Table Tools and Datasheet Tabs
appeared to assist you. The Ribbon below these Tabs is composed of Groups of
selections you’ll use to assist you as you create your Table.
Creating a Table – (cont.)
On the left of the Table Tools-Datasheet Tab/Ribbon you’ll see a View
button. Click the View button.
When you click the View button the image on the left
will appear. Since we want to create or design a new
Table, we’ll click the Design View selection.
NOTE: Access consists of 4 main database objects: Tables, Queries, Forms, and Reports.
Each object has at least 2 views, Design and Data. The Design View is where we build the
structure of that database object. The Data view is different for each object. Tables and
Queries have a Datasheet View, Forms have a Form View, and Reports have a Report
View, or a Print Preview View.
In order to create relationships between tables, the user will need to define a
primary key, or foreign key, for each table in the database.
The primary key will be unique for each and every record. Once a primary key
has been defined, Access will not allow users to enter the same value in a field as
another record. For example, if the user were to define a Personal ID Card
Number field as a primary key, same personal ID card number could not be
entered for two records in the database.
Good Primary Key Not good for the Primary Key
Creating a Table – (cont.)
To “turn off” the Primary Key, click the Primary Key
button. You’ll notice that they Primary Key button is no
longer “orange” and the little key is gone from the left of
ID.
If you want to have a Primary Key, click the Primary
Key button again. Notice, bellow in the “Field properties”
area, “Indexed” is changed to “YES (No Duplicates)”.
Notice, under the Blue Bar at the top of the Design screen there are (3) things:
Field name, Data Type, & Description.
Significant Note:
When creating a database it is always best to “break down” a field into its
“smallest parts.”
For example – Name would break down into First Name, and Last Name (you
could also have Middle, Initial, Title, etc.)
Address would break down into Street Address, City, State, and Zip (you could
also have Apartment Number, etc).
Because we are working in Access 2007 it will be very simple to “put the fields
back together” with a few mouse clicks when we need to do this.
Creating a Table – (cont.)
So let’s create a Employee database.
Look at the image here. Click-in the area or space under
Field Name and type-in FirstName (to replace ID).
Tap Enter or click-in the area to the right under Data
Type. The cursor now moves to the right under Data
Type. Click the down arrow under Data Type on right.
Now notice in the lower part of the screen, under Field Properties, that a box
appeared when you selected the Text Data Type. This box is "tailored" to the
Text Data Type that you selected above. Your Field Properties should look like
the one below when you finish doing the steps indicated below.
Creating a Table – (cont.)
Field Properties: Click-in each area (to the right of the words).
Field Properties
Field Size Is currently set to 255 characters. That's pretty large for a name. So, click-
in this area and change the number to 25 (you can make this larger or
smaller later if you have to).
Format Now click-in the Format Area. Next tap the F1 function key to activate
Help.
Since you are in the Format area, Help will be "tailored to" this area. When the
Help Window appears, click Format Property.
Now click Text and Memo Data Types. Notice that there are several choices to
make your characters upper or lower case. (< : Force all characters to lowercase,
> : Force all characters to uppercase, etc.)
This gives you an idea of some formats. We'll use one later. Now click-on the
“X” in the upper right corner of the Microsoft Access Help – Format
Property Window to close it.
Creating a Table – (cont.)
Field Properties (Contd.)
Input Mask We'll come back to this feature later.
Caption Look at the Light Blue Help area to the right. It explains about
Caption.
Default Value We'll come back to this feature later.
Validation Rule We'll come back to this feature later.
Validation Text We'll come back to this feature later.
Required Look at the Light Blue Help area to the right.
Allow Zero Length Look at the Light Blue Help area to the right.
Indexed Look at the Light Blue Help area to the right.
Unicode
Look at the Light Blue Help area to the right.
Compression
IME Mode Look at the Light Blue Help area to the right.
IME Sentence
Look at the Light Blue Help area to the right.
Mode
Smart Tags Look at the Light Blue Help area to the right.
Creating a Table – (cont.)
Now we’ll repeat this process and create different Field Names and Data Types.
Type-in the Field Names as indicated below and set them to the Data Types and
Sizes indicated.
Now Insert a “ > ” in the Format area to make all gender entries become upper
case (Capitals, i.e. “M” or “F”).
Creating a Table – (cont.)
Now lets interchange the Rows and define “Primary Key” properly as bellow.
Now lets add a “Title” to Field Name and Data Type as a “Lookup wizard”.
You will get the following screen.
Here we'll learn about Numbers, the Validation Rule and Validation Text.
We'll limit the person's favorite number to a number between 1 and 999. Leave
the Field Size set to Long Integer.
Creating a Table – (cont.)
Now click-in the area to the right of Decimal Places. It currently indicates Auto.
Click-on the little down arrow. Select “0”. This indicates that decimal places are
not allowed in the Favorite Number.
Next, click-in the Validation Rule area. We'll "build" a mathematical expression
that will only allow numbers from 1 to 999. Type in the following expression:
> 0 and < 1000
If someone does not enter a number correctly, an error message will appear.
Now we'll create an appropriate error message. Click-in the Validation Text area
and type-in: “Favorite number must be between 1 and 999”
Creating a Table – (cont.)
Continue entering the following information in the Field Name and Data Type
areas as we did above.
DateHired Date/Time
In the Input Mask area click the three dots (...), Save the table, and choose
Phone Number, click Next>, click Next> again, then click Finish. (This will
insert a “ ( _ _ _ ) _ _ - _ _ _ _ _ ” to the Phone number field)
In Format area click the small down arrow and choose Standard (If you use
“Currency”, the values are in $).
In the Decimal Places Field Properties area click-on the small down arrow and
select 0 – this indicates “no cents”. Type a 0 (zero) in the area of Default Value.
This will indicate 0 income if no Salary figure is entered.
Creating a Table – (cont.)
Continue entering the following information in the Field Name and Data Type
areas as we did above.
ApplicationReceived Yes/No
We’ll make this a “Yes/No” or “check box” field. When we begin entering data in
the database, you’ll see how this “box” works.
Some of the Field Names may be “cut off” a bit. Let’s widen our fields.
Move your cursor over the “line” between two Field Names.
Click and hold down the left mouse button and move your
cursor to the right a bit.
Note:
Since we have a Validation Rule in one of our Fields, it is better to widen
columns when you are not entering data, as otherwise it may give error massages.
Save your layout changes of the table Datasheet View.
Entering Data in the Database – (cont.)
Now let’s enter the bellow data in each field of our datasheet.
When you have completed typing the information, tap Enter so the cursor will
move down to the next record. You are now ready to insert your 2nd entry.
Note: When you tapped Enter, Access automatically saved your first record.
Also note: As you began typing your first record a small pencil appeared in the
left margin. This indicates that you are "writing to" this record (editing). Below
the pencil an * (asterisk) also appeared. This indicates that your next record will
go below the first.
Entering Data in the Database – (cont.)
Important
To record enough information so that you can see the power of Access
database does enter 20 or more records now. You may use either
Form View or Datasheet View.