unit 4 – introduction to spreadsheet and database, pages 1...

12
Unit 4 – Introduction to Spreadsheet and Database, pages 1 of 12 Department of Computer and Mathematical Sciences CS 1305 Intro to Computer Technology 15 Module 15: Introduction to Microsoft Access Objectives: - Learn how to use Microsoft Excel. - Learn how to create relational database - Learn how to use relational database. Introduction First of all you need to understand how Microsoft Access breaks down a database. These are the keywords used in Access database structure: Database File, Table, Record, Field, and Data- type. Here is the Hierarchy that Microsoft Access uses in breaking down a database. Database File: This is your main file that encompasses the entire database and that is saved to your hard-drive or floppy disk. For examples: Database1.mdb, PatientDatabase.mdb Table: A table is a collection of data about a specific topic. There can be multiple tables in a database. For examples: Patients, Employees Field: Fields are the different categories within a Table. Tables usually contain multiple fields. For examples: Student LastName, Student FirstName Datatypes: Datatypes are the properties of each field. A field only has 1 datatype. For examples: FieldName: Student LastName Datatype: Text Task 1: Starting Microsoft Access In this task, we will learn how to start Microsoft Access and use commands from F ile menu to create, save, open, and print database. Activity 1.1: Create a new database Look for Access icon on the desktop or from All Programs menu from the Start button . After you click on Access icon either from the desktop on from All Programs menu, a Microsoft Access startup window will appear with Getting Started pane window on the right side as shown in Figure 1. Figure 1: Access Startup window Database File Table Field Datatype Value

Upload: others

Post on 25-Mar-2020

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Unit 4 – Introduction to Spreadsheet and Database, pages 1 ...cms.dt.uh.edu/Faculty/OngardS/cs1305/Labs/Module15_Introduction to Microsoft Access.pdfUnit 4 – Introduction to Spreadsheet

Unit 4 – Introduction to Spreadsheet and Database, pages 1 of 12

Department of Computer and

Mathematical Sciences

CS 1305 Intro to Computer

Technology 15

Module 15: Introduction to Microsoft Access Objectives:

− Learn how to use Microsoft Excel.

− Learn how to create relational database

− Learn how to use relational database.

Introduction

First of all you need to understand how Microsoft Access breaks down a database. These are the

keywords used in Access database structure: Database File, Table, Record, Field, and Data-

type. Here is the Hierarchy that Microsoft Access uses in breaking down a database.

Database File: This is your main file that encompasses the entire

database and that is saved to your hard-drive or floppy disk.

For examples: Database1.mdb, PatientDatabase.mdb

Table: A table is a collection of data about a specific topic. There

can be multiple tables in a database. For examples: Patients,

Employees

Field: Fields are the different categories within a Table. Tables

usually contain multiple fields. For examples: Student LastName,

Student FirstName

Datatypes: Datatypes are the properties of each field. A field

only has 1 datatype. For examples:

FieldName: Student LastName

Datatype: Text

Task 1: Starting Microsoft Access

In this task, we will learn how to start Microsoft Access and use commands from File menu to

create, save, open, and print database.

Activity 1.1: Create a new database

Look for Access icon on the desktop or from

All Programs menu from the Start button .

After you click on Access icon either from the desktop

on from All Programs menu, a Microsoft Access

startup window will appear with Getting Started

pane window on the right side as shown in Figure 1.

Figure 1: Access Startup window

Database File

Table

Field

Datatype

Value

Page 2: Unit 4 – Introduction to Spreadsheet and Database, pages 1 ...cms.dt.uh.edu/Faculty/OngardS/cs1305/Labs/Module15_Introduction to Microsoft Access.pdfUnit 4 – Introduction to Spreadsheet

Unit 4 – Introduction to Spreadsheet and Database, pages 2 of 12

Select New… in the File menu from the menu bar. The right pane window will switch from

Getting Started to New File. Select Blank database… from New File window as shown

in Figure 2.

Figure 2: Access Startup Window

A File New Database dialog box will appear as shown in Figure 3. The purpose of this dialog

window is for you to save the new database that you want to create to a file. So, type in

Database1 to the File name: textbox and click on Create button. Make sure the destination

of the file that you want to save is your flash drive. You should see Database Window

appears as shown in Figure 4.

Figure 3: File New Database Dialog Box

Figure 4: Database Window

Activity 1.2: Create a new table

The following are steps for creating a table in Access:

1. In Database Window, select Tables icon from the command icon list on

the right panel.

2. Click on the New icon from the tool bar of Database Window as shown in

Figure 4.

Click New button to create a new table.

1

2

Page 3: Unit 4 – Introduction to Spreadsheet and Database, pages 1 ...cms.dt.uh.edu/Faculty/OngardS/cs1305/Labs/Module15_Introduction to Microsoft Access.pdfUnit 4 – Introduction to Spreadsheet

Module 14: Introduction to Microsoft Access, page 3 of 12

Naming Conventions

When naming your database tables and fields:

• Use single words; do not use spaces

• If needed, use underscores (_ _ _) as word separators; do not use special characters, such as #, @, ‘, “, $, or –

• Naming is case-sensitive; that is, FirstName is not the same as first name

3. New Table dialog box will appear

as shown in Figure 5. Then, select

Design View from the right

window.

4. Click OK button to accept the

selection to create a new table in the

design view.

5. Table window should appear with a

titled of Table1 : Table as shown

in Figure 6.

Figure 5: New Table Dialog Box

Figure 6: Table Window

Activity 1.3: Define each field in the table

Table is divided into three columns and several rows as shown in the below figure. The three

columns are:

1. Field Name:

2. Data Type:

3. Description:

In this activity you will create a database to store information of patients. Use the following steps

to create a table named Patient Table as follows:

1. In the cell of the first row under the column Field Name, type in

PatientID

2. Press enter or click at the cell in the first row under column Data Type. You will see

a list of data types in a drop-down menu with Text data type is

shown. Since we want the value of PatientID to be a unique number, we will select

AutoNumber as PatientID Data Type.

3

4

5

Page 4: Unit 4 – Introduction to Spreadsheet and Database, pages 1 ...cms.dt.uh.edu/Faculty/OngardS/cs1305/Labs/Module15_Introduction to Microsoft Access.pdfUnit 4 – Introduction to Spreadsheet

Unit 4 – Introduction to Spreadsheet and Database, pages 4 of 12

3. In the next row under the column Field Name, type in LastName

4. Press enter or click at the cell in LastName row under column Data Type and

select Text as the data type.

5. Repeat Step 3 and 4 for FirstName , Address , City, State, and

ZipCode with Data Type as Text except ZipCode is of type Number . 6. Determine the primary key -- a field that can be used to uniquely identify each

record in the table. The primary key also allows you to connect information

from one table to another. Each patient is assigned a PatientID number that

will be a unique identifier. To indicate that PatientID is the primary key, select

PatientID field and click the Primary Key button from the Access window

toolbar . You should the key icon

in front of PatientID field.

7. Save the table by selecting Save from File menu. Name this table Patient Table

and click OK button. The title of the table should change to Patient Table as the

below figure.

8. Ensure that you have set up the table correctly by entering sample data. First,

switch to the Datasheet View by clicking on View icon drop-down menu in the top

left corner of the Access window as shown below.

9. In the Datasheet View, enter information of five patients in the Patient Table as follows:

10. Save and close the table.

Activity 1.4: Create more tables

You will now create two more tables as you did in Activity 1.3 -- The Therapy Table

and the Appointment Table.

1. Create Therapy Table, which has two fields:

• TherapyName (Text data type)

• TherapistName (Text data type)

View icon

Page 5: Unit 4 – Introduction to Spreadsheet and Database, pages 1 ...cms.dt.uh.edu/Faculty/OngardS/cs1305/Labs/Module15_Introduction to Microsoft Access.pdfUnit 4 – Introduction to Spreadsheet

Module 14: Introduction to Microsoft Access, page 5 of 12

Why did I use the Lookup Wizard? You have limited the data entry choices in one column. Now, when you enter data in the TherapyName field of the Appointment Table, the list of available therapies from your Therapy Table will be displayed as a drop-down list.

2. b. Select TherapyName as the primary key. In this case, each therapy has a

unique name, so TherapyName field will uniquely identify each

record in the table.

3. c. Name and save the table as Therapy. Switch

to the Datasheet View and fill the table with

data as shown in the right figure.

Close Therapy Table and then create Appointment Table, which has four fields:

• AppointmentID (Autonumber data type)

• Date (Date/Time data type)

• PatientID (Number data type)

• TherapyName (Text data type)

Select AppointmentID field as the primary key because it uniquely identifies each record

in this table. Name and save this table as Appointment, and close the table. (Do not enter

any data into the Appointment Table for now.)

Activity 1.5 Use lookup wizard to limit data entry choices

We can limit the data entry choices in a particular column by using the Lookup Wizard to

create a drop-down list box that looks up values in another table. A drop-down list box helps to

eliminate typographical errors and duplicate data entries. To create a drop-down list box in the

Appointment Table for TherapyName field, do the following:

1. Open the Appointment Table. In the

Appointment Table’s Design View, use

the drop-down list to change the data type of

TherapyName to Lookup Wizard.

2. In the first window of Lookup Wizard, as

shown in the right figure, select I want the

lookup column to look up the values in a

table or query and then click on Next button.

3. Answer Lookup Wizard’s questions as

follows:

• Which table or query should provide the

values for your lookup column? Select

Table: Therapy Table. Make sure that

Tables is selected in the View box.

Click on Next button as shown in the

right figure.

Page 6: Unit 4 – Introduction to Spreadsheet and Database, pages 1 ...cms.dt.uh.edu/Faculty/OngardS/cs1305/Labs/Module15_Introduction to Microsoft Access.pdfUnit 4 – Introduction to Spreadsheet

Unit 4 – Introduction to Spreadsheet and Database, pages 6 of 12

If no tables are displayed in Relationships window, right-click in Relationships window and choose Show All from the Relationships menu. Show All will display every table in your Relationships layout.

• Which fields contain the values you want included in your lookup column?

Select TherapyName field from the Available Fields box and click the >

button to move it to the Selected Fields list. Then click on Next button as

shown in the figure below.

•••• How wide would you like the columns in your lookup column? Adjust the

widths of your column if needed and click on Next button again. Rename or

accept the lookup column label, and click on Finish button. (If the Save

option pops up, click on Save.)

4. Change to Datasheet View. Click in

the cell under TherapyName to view

the drop-down list. Now, if you want

to change the name of a therapy, you

only need to make that change once in

Therapy Table, rather than in every

appointment record associated with

that therapy! Close Appointment Table.

Activity 1.6: Relate tables so that data are only entered once

Relating two tables allows the information in one table to be accessed from the other table.

To relate two tables:

1. Go to Database1 window (choose Database1 from Window menu in the

menu bar if you are not already there).

2. Choose Relationships button from the toolbar. You will see Relationships

window as shown below.

3. Remember that in Activity 1.5, you related Appointment and

Therapy Tables. You should now see that relationship in the

Relationships window.

Page 7: Unit 4 – Introduction to Spreadsheet and Database, pages 1 ...cms.dt.uh.edu/Faculty/OngardS/cs1305/Labs/Module15_Introduction to Microsoft Access.pdfUnit 4 – Introduction to Spreadsheet

Module 14: Introduction to Microsoft Access, page 7 of 12

Referential integrity” is a system of rules that Microsoft Access uses to ensure that relationships between records in related tables are valid and that you don’t accidentally delete or change related data.

Why did I relate the tables? Now that Patient Table and Appointment Table are related through their PatientID fields, information about the patient does not need to be entered every time a new appointment is made.

4. To show the Patient Table, right-click in Relationships

window to display a menu as sown in the right figure and

select Show Table… From Tables tab, select Patient, and

then click on Add button, and then click on Close button.

5. Drag PatientID field from Patient Table to

PatientID field in Appointment Table.

When Edit Relationships window appears,

check Enforce Referential Integrity, and

then select Create. Now the two tables are

related by PatientID.

6. Right-click on the join line that connects the

Appointment Table and Therapy Table

to edit the relationship. Select Edit Relationship. Select Enforce Referential Integrity, and

then select OK. Save the relationships you have created,

which should now look similar to the following figure:

7. Close Relationships window and select Save if the

Save window appears.

Activity 1.7 Create a form to enter and display your data Now you will create a form to more easily enter and display your data -- in this case, patients’

information and their appointments -- using the Form Wizard.

1. Select Forms from the Object menu and then select New . Choose Form Wizard from the list of methods for creating a form. Leave Choose the table or query where the object’s data comes from: blank and click OK.

Page 8: Unit 4 – Introduction to Spreadsheet and Database, pages 1 ...cms.dt.uh.edu/Faculty/OngardS/cs1305/Labs/Module15_Introduction to Microsoft Access.pdfUnit 4 – Introduction to Spreadsheet

Unit 4 – Introduction to Spreadsheet and Database, pages 8 of 12

2. Answer the Form Wizard’s questions as

follows:

• Which fields do you want on your

form? From Available Fields box,

select the fields that you would like to

appear on your Patient Information

form. Use the > and >> (select all

items) buttons to move your selections

from Available Fields list to Selected Fields list. (Use the Tables/Queries

drop-down list to indicate which table

you are selecting the fields from.)

From the Table: Select:

Appointment Table AppointmentID, Date, and TherapyName

Patient Table PatientID, LastName, FirstName, Address, City, State, and ZipCode

Therapy Table TherapistName

Then click Next. • How do you want to view your data? Select by

Patient Table which will order the records by

patient. In the window on the right, Form Wizard window will show you how your form

will appear. Select Form with subform(s) and

then Appointments appear as a subform click

Next. Because they are organized by Patient.

(Each patient has a collection of appointments.) • What layout would you like for your subform? Select Datasheet and then

click Next. • What style would you like? Choose a style for your form and then click Next. • What titles do you want for your forms? Name your form Patient Information.

You can leave the default name for the subform. Make sure that “Open the form to view or enter information. is selected so you can get a first view

of the form. Then click Finish.

Page 9: Unit 4 – Introduction to Spreadsheet and Database, pages 1 ...cms.dt.uh.edu/Faculty/OngardS/cs1305/Labs/Module15_Introduction to Microsoft Access.pdfUnit 4 – Introduction to Spreadsheet

Module 14: Introduction to Microsoft Access, page 9 of 12

Why did I create these forms? To make entering patients’ appointments so much easier -- and now you’re ready to do it! Notice that the TherapyName field has a drop-down list, and that the cost automatically fills in after you choose a therapy.

At this point, your form should look like the following figure:

3. You may want to use Design View to adjust the size of the form and the Appointment subform if they are not the right size:

• To adjust the size of the form, select Design View toggle button. Click on the edge of

the form and use the arrows to expand its width.

• If all the fields aren’t visible in Appointment subform, click on the edge of it and

use the handles/arrows to expand its width. Since the subform is laid out in

Datasheet form, you only need to adjust the column widths if necessary.

4. You may also move elements on the form, and change the appearance of labels:

• To move elements, use your mouse to drag them to the

desired location.

• To change the appearance of labels, right-click on a

label and select Properties from the menu. Choose

Format and navigate to Font Name to change the

font. Select the desired font, and then close the

Properties window to see your change.

5. To see the working form, switch to Form View by selecting it

from View menu (or click View toggle button). Enter the

appointment information for your five patients, as listed below:

Page 10: Unit 4 – Introduction to Spreadsheet and Database, pages 1 ...cms.dt.uh.edu/Faculty/OngardS/cs1305/Labs/Module15_Introduction to Microsoft Access.pdfUnit 4 – Introduction to Spreadsheet

Unit 4 – Introduction to Spreadsheet and Database, pages 10 of 12

Last Name First Name Therapy 1 Therapist 1 Therapy 1 Date Therapy2 Therapist2 Therapy2 Date

Nobody Joe Shiatsu D. Morewill 12/10/2007 Pilates J. Goodman 12/11/2007

Doe Jane Ultrasound N. Tasety 12/12/2007 Ultrasound N. Tasety 12/20/2007

Somebody Mike Whirlpool J. Goodman 12/1/2007 Storm Bob Shiatsu D. Morewill 12/2/2007 Shiatsu D. Morewill 12/6/2007

Smith John Pilates J. Goodman 12/12/2007

This is what your final form might look like:

Activity 1.8 Generate Reports

To view data about the patients and staff, you will create two reports -- one showing all the

patients’ information, and one showing each therapist and which appointments he or she attended

to. You will create the Patient Information Report first.

1. Select the Reports button from the Objects menu. Select Create report by using wizard, then select

New .

2. Choose Repeort Wizard from the list of methods for creating a form. Leave Choose the table or query where the object’s data comes from: blank and click OK.

3. Select Table: Patient Table from the Tables/Queries drop-down list. From the Available Fields list, move all the fields over t o the Selected Fields list. Click Next.

Page 11: Unit 4 – Introduction to Spreadsheet and Database, pages 1 ...cms.dt.uh.edu/Faculty/OngardS/cs1305/Labs/Module15_Introduction to Microsoft Access.pdfUnit 4 – Introduction to Spreadsheet

Module 14: Introduction to Microsoft Access, page 11 of 12

4. Answer the Report Wizard’s questions as follows:

•••• Do you want to add any grouping levels? Click

Next.

• What sort order do you want for your records? In

the first drop-down list, select LastName so

that the list will be ordered by LastName.

Ascending already appears next to the drop-

down list, so you don’t need to select it. Select

FirstName in Ascending order, and PatientID

in Ascending order.

• How would you like to lay out your report? Make

the selections as indicated in the right figure and

click Next.

• What style would you like? Choose a style and

click Next.

• What title do you want for your report? Title

your report All Patients’ Information.

Page 12: Unit 4 – Introduction to Spreadsheet and Database, pages 1 ...cms.dt.uh.edu/Faculty/OngardS/cs1305/Labs/Module15_Introduction to Microsoft Access.pdfUnit 4 – Introduction to Spreadsheet

Unit 4 – Introduction to Spreadsheet and Database, pages 12 of 12

5. Click the Print Preview button or select Print Preview from the View menu to see

your report. Here is what it might look like:

Print out the report to be turn in at the end of the module.

Lab 15 Exercise

1. Create a Therapists’ Productivity Report that look like the following:

Turn in reports in Activity 1.8 and exercise problems.