Tutorial Access 2007

Download as pdf or txt
Download as pdf or txt
You are on page 1of 25

Tutorial 1

Microsoft Access 2007

In this tutorial we will look at the basics of Microsoft Access 2007. You should first read the
information given in this tutorial and then complete the activities listed throughout.

Starting and Quitting Microsoft Access

To start Microsoft Access:


Click on the Windows Start button; select Programs, then Microsoft Office, and choose
Microsoft Office Access 2007.
Alternatively, if displayed on the screen, double-click on the Microsoft Access icon:

To quit Microsoft Access:


Click the Office Button, then choose Exit (Alt + F then X):

Getting Help using Microsoft Access

There are many ways to get assistance when using Microsoft Access. The help option is
available through the Microsoft Access Help button on the right end of the toolbar:

1
Access Wizards

When you create a new database, table, query, form or report in Microsoft Access, you can
choose whether to start with a blank object and build it yourself or use an Access Wizard to
help you build it. An Access Wizard is like a database expert who prompts you with
questions about the object you want and then builds the object based on your answers.

Task 1: Familiarize yourself with using the Microsoft Access help facilities. Search for
help and ask questions on the following topics: creating tables, data types, primary key,
referential integrity, data validation and the web publisher wizard.

Opening a Database

A Microsoft Access database is a collection of objects, not just a single table of data. One
database file contains the tables as well as queries, forms, reports and other objects that
help us use the information in the database.

When we first load Access, we see something like this:

On the right side we can see the list of the most recently opened databases. However, if we
want to open a database that is not listed we select More…. Once we have made our
selection, we click on Open to continue or Cancel to cancel the operation.

2
To open a database

In general, to view existing databases we select Office Button then choose Open (Alt + F
then O):

This displays the Open dialog box. Once we have located our database and identified the file
name, we choose Open. Microsoft Access provides sample databases in Local Templates
(displayed on the left side of the application window).

Let us open the Northwind 2007 database template. Selecting the location where this
database will be saved, we can have a look at a developed database system.

3
The Navigation Pane

When we create or open a database, Microsoft Access displays the Navigation Pane on the
left side of the Microsoft Access window. The Navigation Pane, together with the Ribbon is
our command centre. From there, we can create, edit and use any object in our database.
For example, (after opening the Navigation Pane shutter bar) we have the following view:

4
Changing the Navigate To Category to Object Type and the Filter By Group to All Access
Objects we will get the list of all objects (Tables, Queries, Forms, Reports, Macros and
Modules) that build up our Northwind 2007 database.

After closing both the Security Warning (if we enable the macros, the database system
becomes operational) and the Startup Screen, we will see the following:

5
Listing all Access objects, the headers in the Navigation Pane provide direct access to every
object in our database. For example, to see a list of forms in the database, click the Forms
header. Under the header Microsoft Access will then display the list of all forms stored in
the database. Alternatively, we can also change the Filter By Group option to Forms (Arrow
Down + F).

6
To view the list of tables, click the Tables header, or select Tables under Filter By Group
(Down Arrow + B).

Viewing Data and Closing Database

To view data in a table

1. In the Navigation Pane, select Tables as Filter By Group option to display the list of
tables in the database.
2. Double-click the name of the table you want to see.

Microsoft Access displays the table in Datasheet View. The datasheet view displays data
from the table in columns and rows, similar to a spreadsheet. In a datasheet, we can resize
and rearrange the columns (fields) and resize the rows (records). We can scroll vertically to
see more records and horizontally to see more fields.

3. When we are ready with the particular table, we can close the Datasheet window.

To view the result of a query

It is just as easy to view a query’s dynaset (dynamic set of data) as it is to view a table. A
dynaset is an updatable type of record set. Any Microsoft Access set of records defined by a
table or query, which we can treat as an object, is a dynaset. We choose Queries under

7
Filter By Group in the Navigation Pane, and double-click the query we want to view.
Microsoft Access will then display the dynaset in datasheet view.

To view data using a form

1. In the Navigation Pane, select Forms as Filter By Group option to display the list of
forms.
2. Double-click the name of the form you want to view. Microsoft Access opens the form
and displays the first record of data.

Forms are displayed in a Form View. We can also display a form in the datasheet view. To
switch from form view to datasheet view, access the View menu and select Datasheet View.
To see how the form was created, we can switch to Design View.

To close a database

Click the Office Button, then choose Close (Alt + F then C).

Task 2: Open, view and close the various objects in the Northwind database. Note that
some objects in this database only allow us to see the data in form view and not in
datasheet view.

Creating a Database

8
When we create a Microsoft Access database, we create one file that contains all the tables
in our database as well as the queries, forms, reports and other objects that help us use the
information in the database.

Microsoft Access provides two methods to create a database. We can create a blank
database and then add the tables, forms, reports and other objects later. This is the most
flexible method, but it requires us to define each database element separately.
Alternatively, we can use a Database Wizard to create in one operation the required tables,
forms and reports for the type of database we choose. This is the easiest way to start
creating our first databases. Either way we choose, we can modify and extend our database
at any time after it has been created.

In the following sections, we go through how to create a database using a Database Wizard
and then how to create a blank database.

To create a database using the Database Wizard

1. Click the Office Button, and select New (Alt + F then N).
2. Click on Local Templates to list the range of databases that we can create with the
Database Wizard. To select the database we need, click the icon. The wizard will create a
database according to what we need to store, enter and for summarizing our data.

To create a database (without Database Wizard)

9
1. Click the Office Button, and select New (Alt + F then N).
2. (Click on Featuring, then select Blank Database.)
3. On the right side, Microsoft Access displays the Blank Database dialog box, which allows
us to create a database from scratch and gives our new database a default name (e.g.
Database1). We can replace this name with any name of our choice.
4. In the File Name box, we can type the name of our database. A database name can
contain up to 64 characters. Microsoft Access automatically appends an accdb
extension to our database filename.
5. To store the database in a different directory or drive, select the location of the file you
want by clicking the icon .

6. Select Create. Microsoft Access creates a database file with a single table (called Table1),
and opens the Navigation Pane.

10
Task 3: Create a new blank database called StayHome.accdb, and save it to your My
Documents folder. This database will hold the tables, forms, reports and other objects
for a video rental shop.

Create a Table

Microsoft Access provides three ways to create a blank (empty) table:


Use the Table Wizard to choose the fields for our table from a variety of predefined
tables (such as business contacts, household inventory or medical records).
Use the Design View to specify all of our table details from scratch.
Enter data directly into a blank datasheet. When we save the new datasheet, Microsoft
Access analyzes our data and automatically assigns the appropriate data type and
format for each field.

Regardless of which method we use to create a table, we can always use the table design
view to customize our table further, such as by adding new fields, setting default values or
creating input masks.

In the following sections we will describe in more detail the process of creating a table by
using a Table Wizard, then by entering data directly into the datasheet, and then by using
the design view.

To create a table using Table Wizard

11
1. Start Microsoft Access, and open the database that is to contain the table.
2. Select the Insert tab and from the Tables group choose Table Templates. In a drop-
down list Microsoft Access will display all the templates that we can choose from.

To create a table by entering data directly into a datasheet

Select the Insert tab and from the Tables group choose Table. Microsoft Access will open a
blank datasheet, where we can start entering our data. What we see now is similar to the
case when we open a blank database, and an empty datasheet is created automatically:

12
When we save the new datasheet, Microsoft Access analyzes our data and automatically
assigns the appropriate data type and format for each field.

To create a table using Design View

Select the Insert tab and from the Tables group choose Table Design. Microsoft Access will
then open a blank table window in design view, and we will see the following:

13
Plan Fields and Data Types

The Field Name identifies the data stored in a field. A field name can contain up to 64
characters, including spaces. The Data Type tells Microsoft Access what kind of data will be
stored in the field (such as text, numbers, dates or currency).

A brief description of the most commonly used data types is given below:

The Text data type is used for words (such as names), for combinations of words and
numbers (such as addresses), and for numbers that are not used in mathematical
calculations (such as telephone numbers). Its field size cannot exceed 255 characters.
The Memo data type is used to store long textual descriptions up to a maximum size of
64,000 characters. Memo fields cannot be indexed. They have no specific format.
The Number data type is used for numbers that can be used in mathematical calculations,
and also for fields that are related to other Number fields or to AutoNumber fields. The
Number data type may be one of the following:
Byte: 1-byte integer (0 – 255)
Integer: 2-byte integer (–32,768 – 32,767)
Long Integer: 4-byte integer (–2,147,483,648 – 2,147,483,647)
Single: 4-byte floating point number (–3.4 × 1038 – 3.4 × 1038 with significant digits ≤
7)
Double: 8-byte floating point number (–1.797 × 10308 – 1.797 × 10308 with significant
digits ≤ 15)

14
Decimal: 12-byte integer with defined decimal precision (–1028 – 1028)
The AutoNumber data type stores sequential numbers created by Microsoft Access. It is a
4-byte integer that is automatically created.
The Date/Time data type is used for dates and times. It is encoded as Double.
The Currency data type is used for currency values such as euros, dollars or yen. It is
encoded as an 8-byte number with significant digits = 4, and no rounding is allowed.
The Yes/No data type is used for yes or no, true or false values. It is represented as a
Boolean data with True = –1 and False = 0.
The OLE Object refers to images, documents, graphs or other objects.
The Hyperlink data type stores Web address.

For details about all data types, click in the Data Type column and press F1 (Help).

Add Fields to the Table

To add a field

1. Type the name of the field to be added in the first empty box under Field Name.
2. Press the TAB key to move to the Data Type box. By default, Microsoft Access gives the
field a Text data type. However, if the field is not text, we will need to select the
appropriate data type.
3. To open the list of alternative data types, click the arrow on the right of the box or press
Alt + Down Arrow.
4. Press TAB to move to the Description box. If required, we can enter a short description
for each field to help us remember the purpose of the field.

15
Set Field Properties

Each field in a table has a set of properties. By selecting the properties of a field, we can
control how Microsoft Access stores, handles and displays data in that field. For example,
we might want our data to be displayed in a particular format. For instance, we might want
to display numbers in scientific notation, or dates with the month’s name abbreviated. The
field property controls how data is displayed in datasheets, forms and reports.

To set a field property

1. Click any box in the row that defines the field to be set.
2. Under Field Properties, click the box of the required property, and then set or select the
appropriate property setting.

16
To delete a property setting

Under Field Properties, select the setting for the property of the field, and then press the
Delete key.

For more information about an individual field property, click the property and press F1
(Help).

To Set a Primary Key for a Table

Open the table in Design View and select the appropriate row(s) that form the primary key
for the table. Then select the Primary Key button on the tab (Design tab, Tools group):

A key icon will appear in the column left-hand side to the field or fields selected to be the
primary key.

In a similar way we can remove the primary key attribute from field(s).

17
To Save a Table

1. Click Office Button, and choose Save (Alt + F then S). Alternatively, we can click the Save
button on the Quick Access toolbar (Ctrl + S) .
2. In case we are saving the table for the first time, we also need to type a name for the
table and choose OK.

To Modify the Design of an Object

1. In the Navigation Pane, we set the criterion for Navigate to Category to Object Type,
and then under Filter By Group we select the type of object (e.g. Tables, Queries or
Forms) that we want to modify.
2. In the list that is displayed, we select the object we want to modify.

Microsoft Access will open a window for the object. Choose the Design View from the View
menu:

18
Note that we can also set the view at the bottom of the application window on the right
side:

Then Microsoft Access will display the object we selected in Design view. The following view
is a snapshot of the Member relation (design view) from the StayHome database (that we
are going to implement shortly…):

19
Task 4: Now we will create four tables for the StayHome database using Design view.
The tables are Member to hold members details, Video to hold details of videos,
VideoForRent to hold the details of copies of videos for rent, and
RentalAgreement to hold the details of video rentals by members.

The Member table has the following fields (with their data types displayed in brackets):
memberNo (AutoNumber), fName (Text), lName (Text), sex (Text), DOB (Date/Time),
address (Text), dateJoined (Date/Time), comments (Memo).
The primary key is memberNo.
Also for this table, set the Format property of the sex field to a Field Size of 1 with an
Input Mask: >L. Also, set this field with a Validation Rule ="M" Or "F" and Validation Text
Please enter M or F.
Remember, if you are not sure about the purpose of the properties associated with each
field, you can (and should) use the help facility by pressing the F1 key.

The Video table has the following fields (with their data types in brackets):
catalogNo (Text), title (Text), category (Text), dailyRental (Currency), price (Currency),
directorNo (Text).
The primary key is catalogNo.

The VideoForRent table has the following fields (with their data types in brackets):
videoNo (Text), available (Yes/No), catalogNo (Text).
The primary key is videoNo.

The RentalAgreement table has the following fields (with their data types displayed
in brackets):
rentalNo (AutoNumber), dateOut (Date/Time), dateReturn (Date/Time), memberNo
(Text), videoNo(Text).
The primary key is rentalNo.
Also for this table, set the format property for the dateOut and dateReturn fields to
Medium Date format (e.g. 10-Oct-00).
Again, remember to use the help facility (F1 key) if you do not understand the purpose of
the properties associated with this field.

In the following there are some snapshots about the design views of the Member and
RentalAgreement relations (so we can take a closer look at the syntaxes of the Input Mask,
Default Value, Validation Rule and Validation Text properties):

20
21
Add and Save Records

Each table in our database has (among others) two views: Design View and Datasheet View.
We can add records to the datasheet view.

To switch to Datasheet view

From the View menu, choose Datasheet View. The arrow at the bottom of the button lists
the alternative views of the table:

To add a record of data

Type in the data values and press TAB to the next field or SHIFT + TAB to the previous field.

To save a record of data

22
Once we have entered all the records we wanted, we press TAB to move to the first empty
field below these records. We are actually not required to do anything else to save our data.
When we leave a record, either by moving to another record or by closing a table, Microsoft
Access will automatically save the data.
Note that the automatic recording of our data only works if we have already created our
table in the design view. If we create a table in the datasheet view by entering data directly,
we have to save the table (with Ctrl + S or clicking on in the Quick Access Toolbar, for
example).

Edit Records and Close a Table

To edit records

There are various ways to edit records. For example:

To move to the next or the previous field, press TAB or SHIFT + TAB, respectively.
To select or deselect the current field, press F2.
To undo changes to the current field or record, press ESC. We can also use Ctrl + Z to undo
our actions.
To replace the value in a field with the value of the same field in the previous record, press
CTRL + '.

To close a table

Click on the right side of the head of the window displaying the table. Alternatively, we
can also use Ctrl + W.

Task 5: Add about 5 records into our Member and Video tables and at least 10 records
into our VideoForRent and RentalAgreement tables. We can use any data.
However, we have to be consistent: The VideoForRent table should hold details of
copies of videos described in our Video table, and the RentalAgreement table
should record the members described in our Member table renting copies of videos
described in our VideoForRent table.

Also, reopen the tables and practice editing the records. Finally, save and close the
tables and exit from the StayHome database.

In the following we can have a look at a sample of the Stayhome database…

23
24
25

You might also like