Microsoft Access 2002 Handouts

13
In this series of four handouts we will provide information to help you get started using Microsoft Access. This program has many capabilities and these handouts only provide a brief introduction! 1. Planning the Database In creating a new database, the most important step is planning and considering what you want to be able to do. Take your time with this step. Sketch out your ideas and share them with others. The answers to these questions will help determine what you can and cannot accomplish with your database. You will need to consider: What is the smallest unit you want information on? For example, do you want to have information on each class or on each individual in the class? Each record will hold information on this unit. What pieces of information do you need to keep? Be practical and think about what you have time to deal with. Also consider how you will keep track of changes in the information. How will you know when information needs to be updated? In what form should you store the information (numbers, text, dates)? You should store numbers that are not used in computations (+,-,*,/) as text fields. For example, you wouldn’t add telephone numbers or zip codes, so those should be stored as text. Which specific fields do you need? For example, do you want just a Name field or do you want a First Name and Last Name field so that sorting can more easily be done alphabetically by last name. Can information stored in one table be linked to another? For example, if you need information on a person’s department, a list of departments can be stored in one table and then linked to an individual. Microsoft Access 2002 for Windows Handout: 1 Academic Computing Support Information Technology Services Tennessee Technological University February 2004 Information Technology Services February 2004

description

Buku Saku Microsoft access ini digunakan untuk pala pemuda

Transcript of Microsoft Access 2002 Handouts

Page 1: Microsoft Access 2002 Handouts

In this series of four handouts we will provide information to help you get started using Microsoft Access. This program has many capabilities and these handouts only provide a brief introduction!

1. Planning the Database

In creating a new database, the most important step is planning and considering what you want to be able to do. Take your time with this step. Sketch out your ideas and share them with others. The answers to these questions will help determine what you can and cannot accomplish with your database. You will need to consider:

What is the smallest unit you want information on? For example, do you want to have information on each class or on each individual in the class? Each record will hold information on this unit.

What pieces of information do you need to keep? Be practical and think about what you have time to deal with. Also consider how you will keep track of changes in the information. How will you know when information needs to be updated?

In what form should you store the information (numbers, text, dates)? You should store numbers that are not used in computations (+,-,*,/) as text fields. For example, you wouldn’t add telephone numbers or zip codes, so those should be stored as text.

Which specific fields do you need? For example, do you want just a Name field or do you want a First Name and Last Name field so that sorting can more easily be done alphabetically by last name.

Can information stored in one table be linked to another? For example, if you need information on a person’s department, a list of departments can be stored in one table and then linked to an individual.

Microsoft Access 2002 for Windows Handout: 1

Academic Computing

Support

Information Technology Services Tennessee Technological University

February 2004

Information Technology Services February 2004

Page 2: Microsoft Access 2002 Handouts

Information Technology Services February 2004

Access 2002 Handout 1 Page 2

2. Creating a new database

In this exercise, we will create our database to track maintenance on “assets”, such as com-puters, from scratch. To begin with, we will create four tables in our database: employee information, a list of departments, asset information, and maintenance information. We will also add a switchboard table to help navigate the database. We will create the database in Access 2000 format which is the default format.

In the PC labs, from the Start menu: Select Programs MSOffice 2002 Microsoft Access

• Select Blank Database under New in the Task Pane to the right of the screen.

• In the PC Labs, browse to your U: drive (My documents folder), and name the database Assets.mdb

• Click Create.

2. Creating tables in Design View

• Under Objects, select Tables • Double-click on Create table in Design

view OR click on New in the toolbar and select

Design View and OK.

The first table will hold information on employees. We will use Social Security number as the employee ID and this will be the primary key for this table. A primary key uniquely identifies each record in a table and can be used to link tables.

• Enter the first field name: EmployeeID • Select the data type: Text • From the menu, select Edit Primary Key

Or right-click on the field and select Primary Key from the floating menu.

Remember that numeric fields are those on which you could do a computation, such as addition or subtraction. Social Security numbers are text fields that consist of numbers.

Page 3: Microsoft Access 2002 Handouts

Information Technology Services February 2004

Access 2002 Handout 1 Page 3

Adding Input Masks

It is helpful for some fields to have predefined input masks to guide data entry.

• Select the table Employees and click on Design in the toolbar. • Click on the Field Name EmployeeID • Under Field Properties at the bottom of the screen, click into the box Input Mask • Then click on the pop-up menu button with three dots. • Click Yes when asked to save the table.

2. Creating tables in Design View (cont.)

Enter the rest of the fields shown here. Note that the field Description is optional, but can come in handy later when someone else takes over your database or to remind you of your design decisions.

In this table, we will use Text, Currency, Date/Time, and Memo field types.

• Click on the x to close the table. • Save it as Employees • Click OK.

Page 4: Microsoft Access 2002 Handouts

Information Technology Services February 2004

Access 2002 Handout 1 Page 4

2. Creating tables in Design View (cont.)

Adding Input Masks

• Select Social Security Number from the list of predefined masks.

• Click in the Try It: box to see how it will appear to those doing data entry.

• Click Next. • Accept the defaults and click

Next and then Finish.

• Click on the Field Name Phone and follow the same steps to create an input mask for phone number.

Formatting Data Display

• Click on the Field Name DateHired

• Under Field Properties at the bottom of the screen, click into the box Format

• From the pulldown menu, select the display format you prefer.

• Close and save the table.

Creating the Departments table

• Under Objects, select Tables • Double-click on Create table in Design view • Create the two fields as shown here and save

the table as Departments.

• Open the table and enter these departments: (Note that the ID is automatically numbered for you).

Biology Computer Science English History Mathematics Physics Sociology

• Then close the Departments table.

Page 5: Microsoft Access 2002 Handouts

Information Technology Services February 2004

Access 2002 Handout 1 Page 5

2. Creating tables in Design View (cont.)

Adding a Lookup Field to the Employees Table

• Right-click on the table Employees and select Design View • Under Data Type for the field Department,

select Lookup Wizard • Select I want the lookup column to look up the values in a table or query • Click Next. • Select the only table listed: Departments and click Next.

• Select both fields by clicking on the double arrow and click Next

• Accept the default: Hide Key Column and click Next

• Accept the suggested name, Department, and click Finish

• When asked to save the table, click yes.

Entering Data into the Employees table:

Double-click on Employees to open the table. Enter the following individuals, noting how the masks and department menu work.

123-45-6789 987-65-4321 John Doe Sue Smith Mathematics Biology (931) 372-1234 (931) 372-8888 08/20/91 8/15/96 $40,000 $35,000

• Close the Employees table.

Creating the Assets Table:

• Double-click on Create table in Design view • Create the fields as shown

above. • Set your Primary Key. • Use the Lookup Wizard for

the field EmployeeID to lookup first and last names of employees to whom each asset is assigned.

• Save the table

Page 6: Microsoft Access 2002 Handouts

Information Technology Services February 2004

Access 2002 Handout 1 Page 6

2. Creating tables in Design View (cont.)

Creating the Assets Table (cont.)

• Enter the following into the Assets table:

Dell Optiplex Dell Dimension $1,700 $1,500 3/5/2003 7/20/2003 GX400 4300 11223344 ABCDEF John Doe Sue Smith

• Close the table

Creating the Maintenance Table

• Under Objects, select Tables • Double-click on Create table in Design view • Create the fields as shown here. • Be sure to set your Primary Key.

• Note that the AssetID field is created using the Lookup Wizard and it consists of three fields AssetID, Serial Number, and Description as shown below.

• Enter the data into the table:

11223344 ABCDEF ABCDEF 11223344 12/3/03 11/8/03 11/30/03 11/15/03 Lost internet connection Email problem Printer Problem Possible Virus Replace Ethernet card Reinstalled software Installed Drivers Disinfected Not Complete Complete Complete Complete $75 $45 $35 $55

Page 7: Microsoft Access 2002 Handouts

Information Technology Services February 2004

Access 2002 Handout 1 Page 7

3. Importing Data into the Employees Table

• From the menu, select Get External Data Import. • Browse to locate the file: Classfiles on Athena ITS Access • Select the File Type:

Microsoft Excel • Double click on the file:

Employees.xls

• The Import Spreadsheet Wizard starts. Note the worksheet is selected and the data appears in the correct columns.

• Click Next.

• Accept the default that the First Row Contains Column Headings.

• Click Next.

• Choose In an Existing Table • Select Employees from the dropdown list. • Click Next.

• Import to table: Employees • Click Finish.

• Open the Employees table & view the data.

Page 8: Microsoft Access 2002 Handouts

Information Technology Services February 2004

Access 2002 Handout 1 Page 8

4. Understanding Relationships

We have created several relationships among our tables by using the Lookup Wizard to define some of our fields.

To see these relationships in graphical form, from the menu select Tools Relationships. If needed, drag and move the boxes to get a clear view. It should look something like this. Close the relationships window.

5. Using the Find Command

The Find Command allows you to find specific records by entering in search parameters.

• Double-click on the Employees table. • From the menu, select Edit Find or click on the binoculars in the toolbar.

• Beside Find What: type Smith • Select Look in: Employees: Table. • Select Match: Any Part of Field • Click Find Next.

• Find all the occurances of the sequece “12”.

Page 9: Microsoft Access 2002 Handouts

Information Technology Services February 2004

Access 2002 Handout 1 Page 9

6. Simple Queries

One of the best ways to view data in Microsoft Access is by using Queries. A Query is a specialized searching tool, similar to Find, except that you do not need to redefine the search each time you run it.

• Click on the Queries button under Objects • Select Create query by using wizard in

the listed options. • Select New in the toolbar at the top of the

window.

In the New Query window:

• Choose Simple Query Wizard

• Click OK.

In the Simple Query Wizard window:

• Click on the drop down box and select Table: Employees

• In Available Fields select LastName

• Click the arrow button to add it to Selected Fields.

• Do the same for FirstName and Phone.

• Click Next

• Accept the suggested title: Employees Query • Click Finish. • View your resulting query.

Page 10: Microsoft Access 2002 Handouts

Information Technology Services February 2004

Access 2002 Handout 1 Page 10

7. Queries in Design View

Simple queries created in the wizard work fairly well for showing basic information. In order to make better use of this database we need to create our own queries and modify queries created by the Query Wizard.

• Click on the Queries button under Objects • Select the Employees Query • Click Design.

The query design screen allows us to make additions or changes to a query. Note the rows in the design table are:

Field: Which field you want to include in the query Table: Which table the field information resides in Sort: How the information in the query will be sorted Show: Whether or not the field will be displayed in the query results Criteria: Used to select a subset of the records Or: Logical or to select additional records

Sort by Name

• Under LastName, from the drop down menu next to Sort: select Ascending

• Do the same for FirstName

• Click on the Datasheet View icon or from the menu, View Datasheet View to see your results.

• Close the query.

Query to list only those with a phone number.

• Right click on the Employees Query and select Copy. • Right click in the empty space below it and select Paste. • Name the copied query: Phone Query. • Open Phone Query in Design View. • Click in the field Phone • In Criteria type: Is Not Null or type: >””

Note: if you wanted to look for a blank field type: Is Null or type =”” • Close and save the changes by clicking Yes. • Double click on the Phone Query.

Notice that it only displays records with a phone number.

Page 11: Microsoft Access 2002 Handouts

Information Technology Services February 2004

Access 2002 Handout 1 Page 11

7. Queries in Design View (cont.)

Query to list only those with a phone number cont.)

• Click on the Design View icon. • Under the field LastName, click in the Sort row and select Ascending. • Do the same for FirstName. • Click on Datasheet View to see the results. • Close the query.

Note that the order of the fields listed determines the order in which the sort will occur. Return to Design View and select FirstName as the first field, then LastName. See how the sort is now by first name and then last name.

Creating a Query from Scratch

• Double-click Create query in Design View • The Show Table window will

appear.

• Select Employees • Click Add • Click Close.

• In the Query window click into the first field and select Department from the drop down menu.

• In the next fields select LastName, FirstName, and Phone.

• Sort ascending in Department, LastName, and FirstName.

• Close and save the query as Departments Query.

• Double click on the query to see the results.

Note: Under Table, Employees was automatically entered because the information comes from one table.

Page 12: Microsoft Access 2002 Handouts

Information Technology Services February 2004

Access 2002 Handout 1 Page 12

7. Queries in Design View (cont.)

Using Criteria

The Like expression inside a query allows a search based on limited similarity. The asterisk * is a wildcard for any expression. Like “Sm*” literally means to search for any record where LastName begins with Sm. We could do Like “*ith*” and the search would return any record that has the string “ith” located somewhere in the LastName field.

• Copy the Employees Query and paste it as Employees Limited Query • Open the Query in Design View • Create the criteria Like “*ith*” • View the results in Datasheet view. • Close and save.

Other examples of query criteria

To specify a time period between two dates: Between #11/1/99 And #11/15/03# To specify a field with a blank in it: “ “ To specify a range: Like “[A-D]*” To exclude a value: Not Like “372*” To specify a range: >=”N” To specify a range: <“N” To specify by specific positions: Left([Phone],3)="931"

Page 13: Microsoft Access 2002 Handouts

Information Technology Services February 2004

Access 2002 Handout 1 Page 13

8. Getting Help

One of the easiest ways to get help with Microsoft Access is the comprehensive online help included with it.

• From the menu, select Help Microsoft Access Help

• For example, click on the Answer Wizard tab and type examples of expressions to find information on this topic.

• Should you have a question that the online help does not address, please contact the Microcomputer Support Office: [email protected]

• Students may call the Helpdesk at 372-3975 or get assistance in the PC labs in person.

• Handouts on using other programs are available on the web under ITS Documentation: http://www.tntech.edu/its/pubs/