microsoft access lab - east carolina...

22
Microsoft Access Lab Create a Database for Emergency Room 11.5.2009 We have been working on data modeling, database management system and Microsoft Access since last week. In this lab session, you will use Microsoft Access to create and link tables, design queries to access data and enter data using forms. The lab session is based on Microsoft 2007 office suite. If you have earlier versions of the Microsoft Access program, the interface will be different. Otherwise, you can use the ECU Virtual Computing Lab to access Microsoft Access 2007. I am going to demonstrate how to use Access 2007 to create the database in class. The session will be recorded and I will make it available online as well.

Upload: others

Post on 21-Apr-2020

6 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Microsoft Access Lab - East Carolina Universitycore.ecu.edu/hsim/zengx/HIMA4160/f09/11b_Access/Microsoft... · Web viewMicrosoft Access Lab Create a Database for Emergency Room 11.5.2009

Microsoft Access Lab

Create a Database for Emergency Room

11.5.2009

We have been working on data modeling, database management system and Microsoft Access

since last week. In this lab session, you will use Microsoft Access to create and link tables,

design queries to access data and enter data using forms.

The lab session is based on Microsoft 2007 office suite. If you have earlier versions of the

Microsoft Access program, the interface will be different. Otherwise, you can use the ECU

Virtual Computing Lab to access Microsoft Access 2007.

I am going to demonstrate how to use Access 2007 to create the database in class. The session

will be recorded and I will make it available online as well.

Page 2: Microsoft Access Lab - East Carolina Universitycore.ecu.edu/hsim/zengx/HIMA4160/f09/11b_Access/Microsoft... · Web viewMicrosoft Access Lab Create a Database for Emergency Room 11.5.2009

1. Launch Microsoft Office 2007 Access from the Microsoft Office Suite. Click the Blank

Database graph under the New Blank Database. Name the file “ER” and choose a place on your

hard drive to save it by clicking on the folder icon. Then click Create button to create the

database.

Click Blank

Database

Name it ER

Page 3: Microsoft Access Lab - East Carolina Universitycore.ecu.edu/hsim/zengx/HIMA4160/f09/11b_Access/Microsoft... · Web viewMicrosoft Access Lab Create a Database for Emergency Room 11.5.2009

2. The default entry point of Access is a New Table in datasheet view. Click on the Design button

on the upper left corner to toggle to design view. A dialog will pop up asking for the name of

the Table. Name it PATIENT. Click OK.

In the design view, please add additional fields to finish the table. The field names and data

types for the PATIENT table is listed in Appendix A.

Page 4: Microsoft Access Lab - East Carolina Universitycore.ecu.edu/hsim/zengx/HIMA4160/f09/11b_Access/Microsoft... · Web viewMicrosoft Access Lab Create a Database for Emergency Room 11.5.2009

You need to create two tables – PATIENT and ENCOUNTER. Please see Appendix A for the name

and property of each field. Pay attention to the field size and data type of each field.

Use Lookup Wizard to define the value of Arrival_Mode in the PATIENT database. You need to

define two columns with the first column as the code and the second column as explanations.

The code and descriptions are as follows:

01 – Emergency Ambulance02 – Patient Transport Service03 – Public Transport04 – Private Transport05 – Walking06 – Police Transport07 – Prison Transport98 – Other99 – Not Known.

You can keep the original primary key ID automatically added by Microsoft Access, or you can

remove the default primary key and make two new ones like I did in Appendix A. If you keep

the old primary keys, make sure you name them MR_NO (in both tables) and ENCOUNTER_ID.

Keep the data type as AutoNumber is OK.

After creating the two tables, your Table work pane should look like this.

Page 5: Microsoft Access Lab - East Carolina Universitycore.ecu.edu/hsim/zengx/HIMA4160/f09/11b_Access/Microsoft... · Web viewMicrosoft Access Lab Create a Database for Emergency Room 11.5.2009

Two new tables here.

Page 6: Microsoft Access Lab - East Carolina Universitycore.ecu.edu/hsim/zengx/HIMA4160/f09/11b_Access/Microsoft... · Web viewMicrosoft Access Lab Create a Database for Emergency Room 11.5.2009

3. Click on the Database Tools tab on the Ribbon. Click Relationships to bring up the dialog for

choosing table to build relationships. Add both PATIENT and ENCOUNTER tables to the

relationship window. Then close the dialog. Clicking the MR_NO field within the PATIENT table,

without release, drop it over the MR_NO within the ENCOUNTER table. A new Edit

Relationships Window will appear. Make sure you check “Enforce Referential Integrity”.

After clicking Create button, you can see the two tables are linked with each other.

Page 7: Microsoft Access Lab - East Carolina Universitycore.ecu.edu/hsim/zengx/HIMA4160/f09/11b_Access/Microsoft... · Web viewMicrosoft Access Lab Create a Database for Emergency Room 11.5.2009

4. Create forms for viewing and entering data into the two tables.

Click on the Create Tab on the Ribbon then More Forms button within the Forms section,

choose Form Wizard to create Forms.

Choose Table: ENCOUNTER from the Table/Queries drop down list. Click the in the center

of the Form Wizard windows to move all fields from the left side of the window to the right side

of the window. You can also use to move the fields one by one.

Page 8: Microsoft Access Lab - East Carolina Universitycore.ecu.edu/hsim/zengx/HIMA4160/f09/11b_Access/Microsoft... · Web viewMicrosoft Access Lab Create a Database for Emergency Room 11.5.2009

Click “Next”. Select the layout that you prefer to use for your form. The default one is

Columnar. Choosing different option will give you the preview of different layout.

Page 9: Microsoft Access Lab - East Carolina Universitycore.ecu.edu/hsim/zengx/HIMA4160/f09/11b_Access/Microsoft... · Web viewMicrosoft Access Lab Create a Database for Emergency Room 11.5.2009

Click Next. Select the style you prefer from the subsequent window. Choosing different options

will give you the preview of the style.

Click Next. Name the form Encounter. Choose Modify the Form’s Design, then press Finish.

Page 10: Microsoft Access Lab - East Carolina Universitycore.ecu.edu/hsim/zengx/HIMA4160/f09/11b_Access/Microsoft... · Web viewMicrosoft Access Lab Create a Database for Emergency Room 11.5.2009

You should see the form design interface like the image below. You can click on a data entry

field to highlight. Feel free to resize or move any entry field to accommodate potential data

after you create the datable.

Page 11: Microsoft Access Lab - East Carolina Universitycore.ecu.edu/hsim/zengx/HIMA4160/f09/11b_Access/Microsoft... · Web viewMicrosoft Access Lab Create a Database for Emergency Room 11.5.2009

.

Press the button on the left upper corner to toggle the mode to view form. You can see

all your fields are listed in a column layout. Please note the form automatically designed the

Arrival_Mode as a drop down list since we used Lookup wizard in our table design. There is no

need to enter any data here yet.

Page 12: Microsoft Access Lab - East Carolina Universitycore.ecu.edu/hsim/zengx/HIMA4160/f09/11b_Access/Microsoft... · Web viewMicrosoft Access Lab Create a Database for Emergency Room 11.5.2009

Follow the same step to create another form for the PATIENT table.

5. Now you have the two forms to enter data into the data tables PATIENT and ENCOUNTER.

Populate some fictional data into the database through the two forms. You need to populate

the PATIENT table first, then the ENCOUNTER table. Please note that the MR_NOs in the

ENCOUNTER table must exist in the PATIENT table first.

At the bottom of the form (in view mode), you can see a row of buttons like

. It is the record navigation bar allows you to go to the

beginning of the records, backward one record, forward one record, , go to the last record, and

enter news record.

Enter three patients and 5 encounters for query practice in next step. Please have one

encounter with the Arrival_Mode as Walking since we are going to use it in our next step.

Page 13: Microsoft Access Lab - East Carolina Universitycore.ecu.edu/hsim/zengx/HIMA4160/f09/11b_Access/Microsoft... · Web viewMicrosoft Access Lab Create a Database for Emergency Room 11.5.2009

6. Query data from the database.

Now you have data in the Access database. You can use query to retrieve the data as you

needed. For example, you might be interested in listing all patients who walked into the ER.

Microsoft Access uses the method Query by Example (QBE) to visually display the query.

First, you need to click the Query Design button on the Create tab to access the Queries work

space.

Click Create query in Design view. You should be able to see the query design view and the

Show Table window.

Page 14: Microsoft Access Lab - East Carolina Universitycore.ecu.edu/hsim/zengx/HIMA4160/f09/11b_Access/Microsoft... · Web viewMicrosoft Access Lab Create a Database for Emergency Room 11.5.2009

Add two tables to the Query Design view by highlighting the table and press Add button. Close

the Show Table window once you have both tables added.

In the first field, choose PATIENT.LName. In the second field, choolse PATIENT.FName. In the

third filed, choose ENCOUNTER.Arrival_Mode. For the Field ENCOUNTER.Arrival_Mode, enter =

“05” into the Criteria cell.

Page 15: Microsoft Access Lab - East Carolina Universitycore.ecu.edu/hsim/zengx/HIMA4160/f09/11b_Access/Microsoft... · Web viewMicrosoft Access Lab Create a Database for Emergency Room 11.5.2009

Save the Query as Patient_Walkin. Press the run button on the Query Design toolbar to run

the query. The result of my query is as follows. Press the SQL view from the dropdown list

Press the SQL view from the dropdown list to view the SQL code behind the scene.

Page 16: Microsoft Access Lab - East Carolina Universitycore.ecu.edu/hsim/zengx/HIMA4160/f09/11b_Access/Microsoft... · Web viewMicrosoft Access Lab Create a Database for Emergency Room 11.5.2009

Other than listing the patients meet the criteria, Microsoft Access can also perform simple

calculation. For example, you want to count the number of patients walked in the ER. You can

use the count expression in Microsoft Access query to calculate the data.

Add the one more field PATIENT.MR_NO to the query design view. Press the button on the

query design toolbar to display the row Total.

The total

row

appears

Press SQL View to

view the SQL code.

Page 17: Microsoft Access Lab - East Carolina Universitycore.ecu.edu/hsim/zengx/HIMA4160/f09/11b_Access/Microsoft... · Web viewMicrosoft Access Lab Create a Database for Emergency Room 11.5.2009

Change the Total cell for the field MR_NO to Count from the drop down list.

Now run the query again. You can see my patients walk in the ER twice.

.

The query we just did is called select query. There are other types of queries available in

Microsoft Access. Click on the button on the query design toolbar to view the choice of

other query. It is not required in this session to design other type of queries, but feel free to try

those.

The total cell is

changed from

group by to count.

Page 18: Microsoft Access Lab - East Carolina Universitycore.ecu.edu/hsim/zengx/HIMA4160/f09/11b_Access/Microsoft... · Web viewMicrosoft Access Lab Create a Database for Emergency Room 11.5.2009

Appendix A: Documentation of the ED database.

C:\Documents and Settings\Xiaoming Zeng\My Documents\AccessLab.mdb Thursday, November 15, 2007

Table: ENCOUNTER Page: 1

Columns

Name Type Size

Encounter_ID Text 10

DateArrival Date/Time 8

TimeArrival Date/Time 8

Arrival_Mode Text 50

Chief_Complaint Text 50

DateDischarge Date/Time 8

TimeDischarge Date/Time 8

DischDx Text 50

MR_NO Text 10

Page 19: Microsoft Access Lab - East Carolina Universitycore.ecu.edu/hsim/zengx/HIMA4160/f09/11b_Access/Microsoft... · Web viewMicrosoft Access Lab Create a Database for Emergency Room 11.5.2009

Table: PATIENT

Columns

Name Type Size

Patient_ID Text 10

LName Text 50

FName Text 50

DOB Date/Time 8

Gender Text 6

Street_Address Text 50

Apart_Number Text 10

City Text 50

State Text 2

Zipcode Text 5

Insurance Code Text 10