Access Notes

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 14

Introduction

Access 2007 is a program that allows you to create and manage databases. A database is a place where
you can store information related to a specific topic. How you intend to use the information will
determine whether you need an Access database or a different program to create and manage your
data.

What is a Database?
A database allows you to store information related to a specific topic in an organized way. In addition to
storing data, you can also sort, extract, and summarize information related to the data. One of the
software programs that allow you to do this is Microsoft Office Access 2007, which is a database
creation and management program.

Why Not Use Excel?


There are many types of data you may need to store and manage: text and numbers, for example.
Depending on what you want your data to do for you, you may or may not need to use a database. You
might be able to use a spreadsheet program like Microsoft Excel. How do you know which data can be
adequately managed with Excel and which data really requires Access to manage it more efficiently? It
depends on how much data you have to manage, and what you want your data to do for you. Let's try to
answer this by looking at a bookstore scenario.

If you work for a bookstore business, you might have to keep track of your customers and their orders.

You could use Microsoft Excel to store and manage this type of data; however, Excel is a spreadsheet
software program that is traditionally used to manage numerical information, like totaling up all
purchases by one customer. While it can do an adequate job at storing some types of text-based data --
like the customer's name and contact information-- that is not really what Excel was designed to do.

Launching Access 2007


To start Access 2007 in the Open Access Labs:
1. Click the Start button at the bottom left corner of the screen.
2. Select the All Programs option.
3. Select the Microsoft Office folder.
4. Click the Microsoft Access 2007 icon.
NOTE: When Access launches without being commanded to open a file, the Getting Started with
Microsoft Access window will appear

Entering Data in Access


Microsoft Access is designed to manage information. Access allows you to enter the client's name,
address, and phone number- the first time they do an order.
Challenge!

Try to answer this questions:

 What is a database?

 What type of software program is Microsoft Office Excel?

1
 What type of software program is Microsoft Office Access?

 Think of at least two differences between Access and Excel.

Opening a Database

You have three main options on the Getting Started page. You can open a template database stored
locally or online, an existing database, or a blank database.

Parts of a Database

A Microsoft Access database is made up of several components including tables, forms, queries, and
reports. These components are called database objects. One or more of these objects are formed when a
database is created, and all the objects appear in the Navigation Pane. To make the database easier to
navigate, beginning Access users may want to reorder the objects in the Navigation Pane.

Tables
A table is the database object that contains the basic information you wish to store
Queries
Another database object is called a query. A query allows you to retrieve information from one or more
tables based on a set of search conditions you define using the table fields.

Forms
A third database object is the form. Forms are an Access tool that users can create to make data entry in
database tables easier. Entering data directly into a table can be difficult if there is a lot of information to
enter. Like an Excel spreadsheet, an Access table is essentially a screen filled with blank rows where a
user enters records. Forms, however, provide users with an easy-to-read interface where they can enter
table data. Forms are especially useful for Access users that aren’t comfortable working with databases.

Reports
The final database object is the report. A report is an effective way to analyze and present data using a
specific layout. The text can be formatted in an Access report, just like it can be in Word documents.

To Close an Object:
 Select the tab for the object you wish to close. (The highlighted tab is the active tab).
 Right-click the tab and select Close from the menu.

Designing a Database

Plan Database Tables


Once you have established the purpose, you can begin brainstorming about how to break the information
up into the tables that your database will need to store the data. Recall that a table is a collection of
records and each record is broken up into the smallest pieces of needed information, called fields.

Since we are planning a database to track our customers, the books we have, and the orders our
customers place, we will need a table for each one of these.

TIP: Keep your database usable to others by giving your tables simple, easy to understand names.

2
CHOOSING A FIELD DATA TYPE
Every field must have a defined data type. The data type determines the kind and range of
Values that can be entered in a field and the amount of storage space available in the field the
Table below lists the data types and their uses.
Text field. Can store any combination of character, which includes; Alphabetical and numb
ers, such as names and address, phone numbers and postal codes, symbols and signs etc. A
Text field can contain up to 255 characters.
Memo data type: contains lengthy text and numbers, such as comments or explanations. A
Memo field can contain up to 64000 characters.
Numbers: numerical data on which you intend to perform mathematical calculations,
except calculation involving money.
Date/time: contains dates and times in are variety of display formats available e.g. short
date, long date, long time etc.
Currency: can store numbers, which have formatted using comas and regional currency
Settings. Don’t use the number data type for currency values because numbers to the height
of the decimal may be rounded off during calculations. The currency data type maintains
fifteen digits to the right and four to the left of the decimal.
Counter: stores sequential numbers automatically inserted by Microsoft Access. Numbering
begins with one, and automatically increases the preceding number by one to get the
succeeding one.
Yes/No: yes/no, true/false, on/off. Takes the fields that will contain only one of two
values. These are the logical data type.
OLE (object linking and embedding) Object: for objects created in other programs using
the OLE protocol that can be linked to or embedded in a Microsoft Access database
through control in a form or report.
Caution: Microsoft Access prohibits the conversation of any field data type to the counter
data type. Instead of changing a data type to counter, add a counter field to your table.
SETTING A FIELD PROPERTY
Each field has a set of properties you use to specify how you want data stored, handed and
displayed. The properties we can set for each field are determined by the data type you select
for the field.
To set a field property
1. In the table’s Design view, select the field whose properties want to save.
2. Click the property you want to set in the bottom part of the window .
3. Set the property
Field Property Description
Field size Maximize the length of a text field or type of number.
Format How data is displayed: Use predefined formats or customize your
own
Decimal places Number of places to the right of the decimal.
Input mask Formatting characters for data entry use predefined masks or
Customize Your own.
Caption Default; field label in a form or report
Default Values value entered in a field when records are created.

3
Validation rule Expression that defines data entry rules.
Validation texts Text that appears when invalid data is entered in the field.
Required Setting that defines whether data must be entered.
Allow zero length Settings that defines whether zero length strings are permitted

Plan Table Fields


Once you know what tables you need, the next step is deciding what fields belong in each table.
Remember that fields are the smallest chunk of information in any record.
Let's look at our Ready-2-Read bookstore example again. There will be several fields in our
Customers table. We'll obviously want their first name and last name. We'll also need an
address if we need to send

the customer his order. Email will be necessary if we need to contact the customer when there is an issue
with their order.

Planned Fields in Customers Table

We will also need several fields in the Books table. Title and Author make sense for books. We'll need a
Price for each book. Category will help us know what type of books sell the best, so we can order more
books that fit into that category.

Planned Fields in Books Table

The Orders table will have fewer fields. We'll need this table to track the Customer who is placing the
order, the Book the customer is ordering, and the Date the order is placed.

4
Planned Fields in Orders Table
Don't worry if your plan doesn't include every possible field you may need. Access lets you add fields to
tables any time you think you need another one!

Setting Up Tables and Fields

When you launch Access 2007, you will see the Getting Started window.

In the left pane, the template categories including the featured local templates are listed, as well as the
categories on Office Online. Templates are pre-built databases focused on a specific task that you can
download and use immediately.

You will also see the New Blank Database option that allows you to build your own database from
scratch.

When you choose the New Blank Database option at the top of this window, you will be prompted
to rename the database from the default name, which is Database1.accdb. Rename the database
whatever you would like the name to be. Click Create to finish naming the database.

Setting up Tables

The new database opens with one table showing as a default. It also defaults to naming this table
Table1 in both the Navigation Pane, and the Table tab itself. You will want to name your tables
based on your database design plan.

Naming a Table

To give the table a unique name, you must first click on the Microsoft Office Button in the upper left
hand corner of the application.

Then, select Save from the menu. The Save As dialog box will appear to let you save the table as
whatever name you choose.

The new table names appear in both the Navigation Pane and the Table tab itself

TIP: Give your tables logical, easy to understand names. To Open a Table
To open a table,

right click the Table name of the table you wish to open in the Navigation Pane. Then, choose Open
from the menu.

Adding More Tables to the Database

5
By default, Access 2007 starts out with one table. To add more tables to the database, click on the
Create tab on the Ribbon. Then, select Table from the Tables command group. A new table will
open in the active database object window. You must name your table using the Save command
from Microsoft Office menu. Naming a Table was addressed on page 3 of this lesson.

TIP: You can tell which table you are currently in by seeing which table tab is highlighted.

Adding Fields to a Table

Access 2007 allows you to add fields to tables when you are:

 working in Datasheet View, which looks like a spreadsheet


 working in Design View, where you are able to set more controls for your fields.

Either way, you need to know how to switch between the two views.

Switching Views
To switch views, select the Views command group from either the Home tab (seen below) or the
Datasheet tab on the Ribbon. Select the view option you would like from the menu.

Adding Fields in Datasheet View


By default, Access 2007 creates one field in each new table, the ID field. This field auto-numbers to give
each record in the table a unique number identifier. Recall that records are the rows in a table.

TIP: You may want to rename the ID field with a unique name, since the ID field appears automatically
in every table you create. While this is not necessary, it may help avoid confusion when setting up table
relationships.

To add more fields to a table in Datasheet View, double click on the Add New Field header.

The Add New Field text will disappear from the header. Name the field by typing the name directly into
the header. Press the tab key on your keyboard to move to the next field.

Adding Fields in Design View


In Design View, the field names are along the left-hand column instead of across the top like in Datasheet
View.

To add a new field to a table in Design View, just click in the cell where you want the new field and type
the field name. When you switch back to Datasheet View, your new field appears as its own column, as
seen below.

In Design View, you have many field property options that you can set to ensure that data can only be
entered in certain formats. Setting these options is a good idea if you want to make sure the data that you
have in your database is good, strong data.

6
Moving Fields
If you want to rearrange the order in which your fields appear in a table, Access 2007 lets you easily
move them around. To move a field in Datasheet View, drag and drop the field to the location you want.
To do this:

 Click on the field header for the field you wish to move.
 Move the mouse in the area of the header.
 When the cross with arrows appears, hold down your left mouse button.
 With the left mouse button still held down, move the cursor to where you would like the field to
appear.
 Release the mouse button and the field appears in its new location.

Deleting Fields
To delete a field in Datasheet View, just click on the field header and then select Delete from the Field
&Column command group. This is found on the Datasheet tab on the Ribbon.

WARNING: You should not delete any field in a table without first knowing what impact the deletion
may have on the rest of the database!

Setting the Data Type for a Field

Access 2007 lets you control how data can be entered in each table field within your database. This is
done using Data Type. The default Data Type is text for every field after the ID field, which was set to
auto number. You can change the Data Type setting:

 from the Data Type & Formatting command group on the Ribbon
 from the Data Type column in Design View

From the Ribbon


To change the data type from the Ribbon, click on the field header. Then, select the data type you want
from the drop down menu next to the Date Type command.

In Design View
To change the data type in Design View, click the field name and then press the tab key on your
keyboard. From the drop down menu under the Data Type column, select the format you want.

The Data Type is more noticeable when the database is being populated with records. It will cause data
to be formatted for currency, text, number, and date/time just in Microsoft Excel.

Challenge!

Open Access 2007 and build your own database:

 Give Table1 a new name


 Add a new table
 Add fields to a table
 Set the data type for a field in a table

7
 Open and close the tables
 Move a field in a table
 Delete a field in a table

Building Table Relationships

Establishing Relationships

To establish a relationship between tables:

 Click the Relationships command in the Show/Hide group on the Database Tools tab in the
Ribbon.

NOTE: Tables must be closed in order to establish relationships.

When the Show Table dialog box appears:


 Select each table name and click Add for the tables you want to relate.
 When you are done, Close the Show Table dialog box.

You should now see a relationship map that contains all the tables that were selected.

Moving Tables in the Relationship Map

To move a table that appears in the relationship map:

 Place your mouse over the table you want to move.


 Hold down the left mouse button, and drag the table to a new location.
 Release the mouse button to drop the table in its new place.

Understanding the Relationship Map

The relationship map lists all of the tables that were selected to relate, and all of the fields that were set up
for that table previously. Notice that the first field has a key icon next to it. This is the Primary Key for
the table.

Primary and Foreign Keys

A Primary Key is the first field in each table of the database. You may recall that this field auto numbers
by default, so that every record in the table has its own unique number to identify it. Access uses this
number to quickly pull information together for you when you run queries or reports, which are covered
later.

A Foreign Key is a field that is the Primary Field in its own table, but that shows up in another table..
These fields are the primary key in their own tables, but in anather table, they are considered Foreign
Keys.

Relating Tables

8
There are a few ways to establish relationships between tables:

 Using the Edit Relationships command located on the Design tab of the Ribbon
 Using the Drag and Drop method

Both methods give you the same end result, but the Drag and Drop method is much easier and saves you
several steps.

 Drag the field name from the one table to the other table in the desired relationship.

 Drop the first field name onto the field name that you want to relate by releasing the left mouse
button.

 The Edit Relationships dialog box appears.Relating Tables with the Drag and Drop Method
It is easy to relate tables from the relationship map:

 Select a field name from one table by holding down the left mouse button.

 Select the Enforce Referential Integrity option. This option is explained in detail below.
 Click Create.

Understanding Types of Relationships

Access 2007 allows for several different types of relationships. These include:

 One to One
 One to Many
 Many to Many

The relationship type you will come across most frequently, and the one created in our bookstore
scenario, is the One to Many relationship.

One to Many

The One to Many relationship means that data for that field will show up a single time in one table, but
many times in the related table.

For example, let's look at one of the book titles in our bookstore. The Book ID for that book should
appear only once in the Books table, because that table lists every title that we stock. But it will probably
appear many times in the Orders table, because we hope that it gets ordered by many people many times.

The symbols for the One to Many relationship look like this:

Enforcing Referential Integrity


In the Edit Relationships dialog box, an option to Enforce Referential Integrity appears.

9
You should click Enforce Referential Integrity to make sure that we NEVER have an order for a book
that doesn't appear in our Books table. Selecting this option tells Access to check for these things when
someone is working with your data records.

Editing Existing Relationships

Access 2007 allows you to edit relationships that already exist. This can be done using the Edit
Relationships command on the Ribbon. However, a much simpler way is to simply double click on the
link that appears in the relationship map. Either method brings up the Edit Relationships dialog box,
where you can change your settings.

Data Validation

Data Validation is a very important database concept. It is the process by which Access tests the data
that is being entered into the database, to make sure it is in an acceptable, or valid, format.

Imagine that one of your database users has entered an order date of January 4, 2008 in the
month/date/year format, as 01/04/2008. Another user has entered an order placed on that same date in the
day/month/year format, as 04/01/2008. Now, if the database is tracking all sales for the month of January
2008, it may not show both orders as placed in January, even though both were placed on the same date.

Access 2007 allows you to set field properties and data validation rules, to force the person entering
data to follow a specific format.

Data Types and Validation Rules


Data Validation begins when data types are set during the process of building tables and fields. For
example, if a field data type had been set to Currency and a text value is entered in that table field during
data entry, Access will not accept an invalid format and will display a validation error, like the one below.

Data validation is accomplished by setting data validation rules and other field properties for various
fields.

Setting Data Validation Rules

 In Design View, highlight the field that requires a validation rule.


 In the Field Properties section at the bottom half of the window, set your validation rule using
the Expression Builder. The expression builder offers common syntax to set up a data validation
rule.
 Validation rules work most easily with numeric fields. Rules for text fields require you to enclose
each acceptable value inside its own quotation marks, separating them with Or, as seen above.

Validation Text
Validation Text is a specialized error message that you can set to have Access tell the person
entering data the specific way you would like them to enter it.

10
To set the Validation Text, enter the error message exactly as you want it to appear to your user
in the row directly beneath the Validation Rule row in the Field Properties section of Design
View. For the validation rule that we set for Category, you would set the validation text like this

Using Field Properties to Ensure Data Integrity

Another way to ensure data integrity is by setting field properties such as Field Size, Format, and
Required.

 Field Size can be set to hold a specific number of characters, up to as many as 255 for text fields.
If you were using a text field to hold the two letter state postal abbreviation, the field size could
be set to 2 to ensure that no one enters a full state name into this field.
 The Format field property can be set to display text or numbers in a standardized way. For
example, text can be set to show as all uppercase and numbers can be set to show scientific
numbers, percentages, or decimals.
 Set the Required property to Yes if you want the person entering data to be required to enter
something in the field. Choose No if the person entering data is allowed to leave the field blank.

These are just some ways Access helps you ensure that data being entered into your database is valid.

Creating and Using Forms

Why Use Forms?


In real life, a form is piece of paper that you fill out so that someone can collect and keep track of specific
information about you. Only one record, your record, is captured with any given paper form. Access 2007
forms work very much the same way.

Creating a Form

Access 2007 has several automatic tools for creating forms. These tools are located in the Forms group
on the Create tab in the Ribbon, as seen below:

The Access 2007 forms tools include:

 The Form command makes a basic form, showing a single record at a time.
 The Split Form command creates a form showing one record on top, and includes the datasheet
view of entire source table on the bottom.
 The Multiple Items command creates a form that shows all the records at once, which looks very
similar to the source table in datasheet view.
 The Form Wizard is hidden under the More Forms command. It walks you through the process
of creating more customized forms.

To Create a Form using the Form Command


The basic Form command is the one we suggest, because it allows the person entering data to see just
one record at a time. It also includes all the fields in your source table for you, and you can modify the
layout of the basic form to hide fields or add controls.

To create a form using this command:

11
 Begin by highlighting the table you wish to use as a source table.
 With the source table highlighted, select the Form command from the Forms command group in
the Create tab on the Ribbon.
 The new form is created and opens in the object pane.

The newly created form has the same name as the source table by default. You can give the form a new
name by saving the form. You will be prompted to give the form a name.

Using Forms to Enter Data

Populating a database is easy once you have a basic form in place. Record navigation works the
same way for forms as it did for tables. The Navigation Bar is located in the bottom left of the
object pane. The Navigation Buttons work the same way they did for the tables, also. The
following picture shows the navigation buttons for a form.

To Add a Record using a Form

To add a record to the database using a form:

 Navigate to a new record, either by using the New Record navigation button, or the New
command in the Records group on the Ribbon.
 Then, simply add the new data.

Your data must be entered using an acceptable format. The acceptable formats were
established when the field properties were set.

Finally, you must save the record.

Save by using either the Save command on the Ribbon, or by progressing to another
record using the New (Blank) Record navigation button. Moving to a new record saves
the most recently entered record. However, it may be necessary to refresh the table in
Datasheet View to see the newest record.

8
Queries
You use Queries to view, change, and analyze data in different ways. You can
also use them as a source of records for forms and reports.
To Create a Query:
1) Click the Create tab on the Ribbon
2) Click Query Design icon
3) Double-click Create Query in Design View
4) Select the table that you would like to base your Query on
5) Click Add
6) Close the Show Table window

12
The table(s) will now be displayed in the upper part of the Query Design Screen by
boxes containing the tables’ fields.
7) Double click on the field names in the field list window which you would like to
includein the Query
Defining Criteria in the Query
In order to control which records are displayed, you must define criteria in a Query. The
most common type of Query is the Select Records Query which will be discussed
below.
To Define Criteria for your Query:
1) Position your cursor in the criteria row in the field for which you wish to define the
criteria for
2) Enter the criteria Example: To find all people it the table who live in Edison

Position your cursor in the


criteria row
of the City field

Type
Edison

Click the Run Query button
Below is a picture of the results of the above query:
The result of a query is called a recordset
. A recordset can be sorted, printed or filtered in the same manner as a table.
To Save the Query:
1) Click the SaveIcon
2) Enter a name for the Query
3) Click
OK
Note: When saving a select Query, you are saving the question that you are asking, not
the results that you see when you run the Query.
dtsdesdesssdssdsdsdsssssCreating a Form Using the Forms
Wizard
A form is a database object that is used to enter or display data in a database.
To Create a Form Using the Wizard:
1) Navigate to the table you want to base the form on
2) Click Create on the Ribbon
3) Click Forms
You are able to navigate using the navigation arrows at the bottom of the form.
Note: The form feeds the table. If you edit a record on the form, or create a new record,
that data will be passed to the table it is associated with.
To Enter a Record on the Form
1) Click the Viewbutton on the Ribbon to switch from Layout View to Form View
2) Enter the data for each field in the record, pressing the Enter key to move to the next
field

13
3) Press Enter after you have entered data for the last field This will send the record to
the table.

14

You might also like