introduction to - chescolibraryjtc.files.wordpress.com · access opens with the assumption that you...

34
John W. Jacobs Technology Center 450 Exton Square Parkway Exton, PA 19341 610.280.2666 [email protected] Introduction to Microsoft Access 2007

Upload: phungthien

Post on 07-Sep-2018

213 views

Category:

Documents


0 download

TRANSCRIPT

John W. Jacobs Technology Center

450 Exton Square Parkway

Exton, PA 19341

610.280.2666

[email protected]

www.ccls.org

Facebook.com/ChesterCountyLibrary

Introduction to

Microsoft Access 2007

1

Introduction to Microsoft Access

What is Microsoft Access?

Access is tool for storing and retrieving data. Unlike Word or Excel, Access does very little on

its own.

Information management tool

Stores data for reference, reporting and analysis

Access is a relational database

What is Data?

A collection of facts

Three types of data that we will be using tonight:

o Text

o Numeric (Number)

o Date/Time

How is Data Organized?

Data is organized into tables

o A table is a collection of information, for example a table of CD’s might include:

CD Name

CD Artist

CD Song Title

o Information in tables can be related for example

Rooms Table (i.e. Living Room, Kitchen, Bedroom)

Inventory Table (i.e. Television, Game Console, Jewelry)

The Television is in the Living Room

o Tables look like an Excel Spreadsheet

How is Data Manipulated?

Forms

Reports

Queries

Let’s Get Started Locate the icon for Access (it looks like a key on a maroon background) and double click. You will see

the following screen:

2

Microsoft has provided several templates to make the use of access easier. For example: Assets,

Contacts, Issues, Events, etc. If your needs are such that you can use the one of the templates, you will

find that they are well done with all of the databases, forms, reports, etc. ready for you to simply enter

data.

Instead, we are going to start with a blank database, so please click on the “Blank Database” Icon at the

top:

3

We will need to enter a name for this database:

Type: HouseholdInventory and click the create button. Notice how the default view looks a lot like an

Excel spreadsheet – rows down the side and columns (although without labels) across the top.

Access opens with the assumption that you want to start with a table, which makes sense since Access

wants to help you manipulate data and without data you have nothing to manipulate.

4

Time for a quick segue into efficiencies in tables and one of the underlying principles of data contained in

a database that of Normalization. Basically normalization is the elimination of redundancy in a table.

Let’s look at a simple example. Picture two people with a few favorite colors.

Person Favorite Color

Jane BROWN

Jane GREEN

Bill BLUE

Bill RED

Bill GREEN

Where is the duplicate information? Jane is repeated twice, Bill three times, and the color Green twice -

although in the sense of normalization GREEN is not subject to normalization since it is tied to the person

rather than the actual color.

Normalizing the information would cause us to create two tables, a table of people and a table of colors.

We would then create a relationship between the tables. For example:

Person Favorite Color

Jane BROWN

GREEN

Bill BLUE

RED

GREEN

The table “Favorite Color” is related to the “Person” table. Now instead of five rows with Jane and Bill

repeating, we have two rows – one for Jane one for Bill – and five rows in the favorite color table. What

are the advantages of doing this? If we change a person’s name (for example, Bill becomes William) we

only have to make the change in one place whereas in the previous example it would have to be changed

twice. Imagine the number of changes if instead of a favorite color Bill was creating a table of all the

books he’s read. Without normalization, if Bill changed his name to William you would have to change

hundreds of records – and what if you made a spelling error?

5

We are going to change the way we create a table, so right click on the tab titled “Table1” and on the drop

down, click “Design View”:

We will have to save the table first, so enter a table name of Assets and click OK.

6

Although not required, every table row should have some kind of unique identifier. Since we cannot

force the elimination of duplicate data (i.e. what if you have two TVs in the bedroom?) Access provides a

way to make each row unique by starting each table with a default column titled ID. This column’s value

will start with zero and Access will automatically increment it each time a new row is added.

So let’s all press the down arrow (you can also use the mouse to position to the next row on this screen)

so that we can define and title the various columns that we want in our database: Here is what we want to

create and the following is the screen shot showing the fields filled in:

Field Name DataType Description

ID AutoNumber

AssetName Text Asset Name

Room Text Room Location

Brand Text Brand Name

SerialNumber Text Serial Number

PurchaseDate Date Purchase Date

OriginalCost Number Original Cost

ReplacementCost Number Replacement Cost (optional)

A few things to note, the column labeled Description is optional, but it is important and a good habit to

get into, so please put this information into your table.

7

This is how our screens should appear.

Now let’s save the table by right clicking on the tab “Assets” and select Save. Then right click again on

the tab and select close.

We can actually enter data into the table now. The screen will look a lot like an Excel spreadsheet.

Double click on the Assets Table (if you want to follow along) and enter data. Note that the ID field

automatically incremented by 1.

8

We are going to create one more table and title it “Rooms”. Click on “Create” in the toolbar, click on

Table and change to “Design View”, name the table “Rooms” and add two fields: ID with a datatype of

Autonumber (automatically created for you) and Room with a datatype of Text. It should look like the

following:

Save and close the table and now let’s create a form! From the main screen insure that the table Assets is

highlighted, click on Create and then click the Form Icon:

9

Access has automatically created a form for us with all of the fields from the table displayed on the form.

Notice that every field (or column) in the table has now been put onto a form, a title has been inserted in

front of the field and you are now ready to save the form and enter data. The view you are looking at is

called “Layout View” and will not support data entry. Instead this view is used to make adjustments to

the form to make it usable for data entry. So let’s do some changes.

First thing we are going to do is to delete the ID field from the form. Why? It’s really not needed since

Access will increment the value regardless of whether it is showing up on the form and Access prevents

us from entering data anyway.

This is your first foray into a field called “GUI Design”. GUI is Graphical User Interface. In this case we

made the decision to make the form easier to understand by eliminating a field that was not required and

wouldn’t let us enter data anyway.

10

Notice as well that Access put labels next to the fields that are the same as the column titles. We can

easily change that by double clicking inside the field and changing the text to something that may be a bit

easier to read for example on the ReplacementCost field, we can add the words “(optional)”.

Note that when we change the title that all of the fields realign themselves.

Now let’s save the table by right clicking on the “Assets” tab (the form name) and select save.

And now its time to enter some data. Again, right click on the “Assets” tab and select “Form View”.

11

Before we actually enter data let’s look at the form. Note on the bottom of the form the line that begins

“Record”. Immediately next to that label is a number which indicates the number of records in the table

and the record number associated with the data displayed on the form (more on this later). Next to that is

a couple of direction buttons (previous, last, next), a filter selection and a search box. The last two (filter

and search) are inoperable until there is actual data in the table.

So let’s input some data. Use the following information to enter five records into the table:

Asset Room Brand Serial

Number

Purchase

Date

Original

Cost

Replacement

Cost

TV Living

Room

LG 1234ABC 12/25/2012 699.00

Couch Living

Room

Raymour &

Flanigan

09/15/2011 1299.00 1299.00

HTC Phone Den HTC 435AP987TH 08/12/2011 99.00 399.00

TV Master

Bedroom

SONY 436A89B3 06/03/2010 899.00 899.00

iPad Den Apple 765HG12-98 11/13/2012 899.00 899.00

Gateway

Laptop

Den Gateway GW87931Z 04/15/2012 499.00 499.00

When finished our screen should look like the following. Notice at the bottom of the screen we now have

Records 7 of 7. If we press the previous record button all the navigation buttons will now show: first,

previous, next, last and new (indicated by an arrow pointing right with a yellow asterisk). Notice also that

the Search feature will now work. Type TV into the Search box and notice that Access automatically

positions you to the first record that contains TV. Notice also that it didn’t matter what field TV was in.

Try it with Raymour.

12

Now let’s create a report, but first, lets close the form. This can be done by right clicking on the tab

“Assets” and selecting Close or by clicking on the x to the right of the Assets tab (on the far right side of

the form).

When you close the form, Access will ask you if you want to save the form, be sure to answer Yes and

then name the form “Asset DataEntry”

We are going to use the built in wizard to create our report.

Make sure that the table Assets is highlighted then let’s click on Create once again and select Report

Wizard.

13

Once we click on the report wizard Access asks us which fields from the highlighted table we want on the

report. You can actually change the table by clicking the drop down arrow in the field “Tables/Queries”

and select a different table, but for our purposes we will only be using the Assets Table so we are good.

We add fields to our report by highlighting the field in the column Available Fields and clicking on the

button pointing to the right or by double clicking on the field name. If we wanted all the fields we would

simply click on the button with the double arrows.

Below that is a button pointing to the left which will remove a highlighted field on the right and if you

were to click the double arrow pointing to the left, all fields would be removed from the report.

14

For now, let’s pick AssetName, Room, Brand, Serial Number, PurchaseDate and Original Cost and click

Next.

Once we have picked the fields and clicked Next, the wizard wants to know if we would like to group the

data on the report. What this means is that all records with the same grouping (for example by room) will

be listed together, regardless of the order in which they were entered.

Let’s group by Room. Highlight the field “Room” and click the arrow pointing right.

15

Notice that the field Room is now located above the other table fields. Click Next.

The wizard will now allow us to sort the records. For example alphabetically by Asset Name.

Click on the down arrow in the highlighted box and select AssetName and click Next.

16

The wizard now wants us to select a layout and an orientation. If you click each of the radio buttons the

wizard will show you how the report will look if printed. Encourage the students to do this.

If you feel that there is too much information to fit on a portrait page (8.5 inches wide by 11 inches tall)

you can select landscape mode (11 inches wide by 8.5 inches tall). You can also stipulate that the field

widths be adjusted so that all the fields fit on a single page. Sometimes this will result in truncation of

data so be careful.

We can now pick a style. Again, clicking on each style will show you the fonts, the font sizes and the

colors used for each style. For now let’s leave the style alone and click next.

17

Now the wizard wants us to title the report so let’s call this report “Household Inventory” and click

Finish.

Hmmm doesn’t look so good does it? The purchase date field is showing ##/##/#### and the cost field

isn’t showing anything but a #. When Access prints a # sign, that indicates that the contents of the field

exceeds the size of the place holder on the report. Let’s fix that by making some room on the right side of

the report so that we can expand the fields.

18

Right click on the “Household Inventory” tab and select Layout View.

We can now begin to adjust the report. Let’s start with the Asset Name by clicking on the title

“AssetName”. If we move the mouse over the dotted lines below the heading, the pointer will turn into a

double pointed arrow. This may take some finessing since you have to be right over the dotted line on the

left so we’ll pause until everyone has the pointer on the dotted line.

Now, with the mouse showing a double pointed arrow, hold the left mouse button down and move the

mouse to the left, adjusting the size of the field.

19

While you are moving the mouse you should see something like the following:

Now repeat the process for the Brand field and the SerialNumber field.

20

That’s starting to look better, we have some room to play with on the left side of the report. Now we are

going to expand the size of the PurchaseDate and the OriginalCost fields. Now instead of moving the

cursor to the left, move the cursor to the right. Repeat for the Original cost field. Wait a second, look at

the first field on the report. Shouldn’t that be bigger as well? Lets increase the size of it too.

That looks great!

21

Now let’s switch back to Report View.

We now have a finalized report which is quite readable and can be printed to be sent to your insurance

agent or kept in a strong box.

But we aren’t done yet! Remember that table we created called Rooms? Let’s explore how that can be

used to make this database truly a relational database.

We are not going to create an input form for this table since it wll only have a few records in it. We’ll use

the default input method provided by Access.

22

Use the following to populate the Rooms Table:

Room

Living Room

Den

Master Bedroom

Dining Room

Bedroom 1

Bedroom 2

When complete you should have the following:

23

Now close the table. Note the numbers along the left side of the table do not have to be the same value as

mine. Close the data input screen.

Double click on the Assets Table to open it and switch to Design View. Add a new field titled RoomID

with a datatype of Number.

When you’ve finished the table design should look like the following.

Now save the changes (Left mouse click on the Rooms tab and select close – then answer YES to save the

changes).

24

Now we will create a relationship between the Assets Table and the Rooms Table. Click on Database

Tools and select Relationships:

Highlight the Assets Table (single left mouse click) and click Add. Do the same for the Rooms Table and

click Close.

25

This is what your screen should look like now.

Using the mouse, move the cursor over the bottom of the Assets box until it changes to a double arrow,

then hold the left mouse button down and drag the size of the box to reveal the other fields in the table.

Move your mouse pointer until it rests on top of the field “RoomID” in the Assets Table. Hold the left

mouse button down and move the mouse pointer until it resides on the field ID in the Rooms Table then

let the mouse button up. Click the “Create” button.

26

We now have a relationship between the Assets Table and the Rooms Table. This will allow us to build a

query that retrieves information from both tables with one query. Information that will always be related.

In other words if we put the Room number into the Assets Table, Access will retrieve the room name

from the Rooms Table based upon the room number in the Assets Table.

Now let’s create a query to demonstrate this principle. A query is simply a way of retreiving data from a

table or tables. We start by clicking on Create then click on Query Wizard.

27

We are going to start our query with the Asset Table since it contains the information that we want to see.

We want all the fields from the Assets Table except the Room field and the RoomID Field we created

previously.

Next we will select the Rooms Table and the Room Field:

28

Access then wants to know if we want a summary of the data or each record that will be retrieved. We

want all the detail records, so click Next:

The default name assigned by Access is fine so let’s click on Finish.

29

Uh oh … we didn’t retrieve any records! Although we have built a relationship between the Assets Table

and the Rooms Table, we did not put any values in the Asset Tables that completed the relationship.

Let’s open the Asset Table by double clicking on the Asset table name and using the following data, let’s

put some additional information in the table. In order to see the proper results of the query we just built

we have to add tell Access exactly how each record in the Assets Table is related to a record in the Rooms

Table. The relationship that we built previously simply tells how the two tables are related. Now we have

to tell Access how each record is related. The column we will be populating is the RoomID field from the

table below:

Asset Room Brand Serial

Number

Purchase

Date

Original

Cost

Replacement

Cost

RoomID

TV Living

Room

LG 1234ABC 12/25/2012 699.00 1

Couch Living

Room

Raymour

& Flanigan

09/15/2011 1299.00 1299.00 1

HTC Phone Den HTC 435AP987T

H

08/12/2011 99.00 399.00 3

TV Master

Bedroom

SONY 436A89B3 06/03/2010 899.00 899.00 5

iPad Den Apple 765HG12-98 11/13/2012 899.00 899.00 3

Gateway

Laptop

Den Gateway GW87931Z 04/15/2012 499.00 499.00 3

One you have completed populating the fields, the table should look like this:

30

Now click on the Assets Query Tab, but notice that we still have no records. Although we have made

changes, Access is a bit slow on realizing how that affects views that are already open.

Click on the Refresh button on the Ribbon:

31

That’s better! We now have the information populated from the Rooms Table. Let’s do a quick exercise

to show you exactly how a relationship works.

Let’s open the Rooms Table and change record number 3 from Den to Office:

32

Now let’s go back to the Assets Query and click Refresh. Notice that every record that used to have

“Den” in the Room name is now “Office”. This is one of the most important features of Access. When

you build a relational database, you only have to make a change to one record but the change is populated

throughout the database.

33

For more information on Microsoft Access, please visit our blog:

http://chescolibraryjtc.wordpress.com