You are on page 1of 18

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 2 ! office suite. If you have earlier versions of !.

the Microsoft Access "rogram, the interface will be different. #therwise, you can use the $%& 'irtual %om"uting (ab to access Microsoft Access 2 I am going to demonstrate how to use Access 2

! to create the database in class.

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

). (aunch Microsoft #ffice 2

! Access from the Microsoft #ffice *uite. %lick the +lank

,atabase gra"h under the -ew +lank ,atabase. -ame the file .$/0 and choose a "lace on your hard drive to save it by clicking on the folder icon. Then click %reate button to create the database. %lick +lank ,atabase

-ame it $/

2. The default entry "oint of Access is a -ew Table in datasheet view. %lick on the ,esign button on the u""er left corner to toggle to design view. A dialog will "o" u" asking for the name of the Table. -ame it 1ATI$-T. %lick #2.

In the design view, "lease add additional fields to finish the table. The field names and data ty"es for the 1ATI$-T table is listed in A""endi3 A.

4ou need to create two tables 5 1ATI$-T and $-%#&-T$/. 1lease see A""endi3 A for the name and "ro"erty of each field. 1ay attention to the field si6e and data ty"e of each field. Use Lookup Wizard to define the value of Arrival7Mode in the 1ATI$-T database. 4ou need to define two columns with the first column as the code and the second column as e3"lanations. The code and descri"tions are as follows8 01 Emergency Ambulance 02 Patient Transport Service 03 Public Transport 04 Private Transport 05 Wal ing 0! Police Transport 0" Prison Transport #$ %t&er ## 'ot (no)n* 4ou can kee" the original "rimary key +, automatically added by Microsoft Access, or you can remove the default "rimary key and make two new ones like I did in A""endi3 A. If you kee" the old "rimary keys, make sure you name them M/7-# 9in both tables: and $-%#&-T$/7I,. 2ee" the data ty"e as Auto-umber is #2. After creating the two tables, your Table work "ane should look like this.

Two new tables here.

;. %lick on the ,atabase Tools tab on the /ibbon. %lick /elationshi"s to bring u" the dialog for choosing table to build relationshi"s. Add both 1ATI$-T and $-%#&-T$/ tables to the relationshi" window. Then close the dialog. %licking the M/7-# field within the 1ATI$-T table, without release, dro" it over the M/7-# within the $-%#&-T$/ table. A new $dit /elationshi"s Window will a""ear. Make sure you check .$nforce /eferential Integrity0.

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

<. %reate forms for viewing and entering data into the two tables. %lick on the %reate Tab on the /ibbon then More =orms button within the =orms section, choose =orm Wi6ard to create =orms.

%hoose Table8 $-%#&-T$/ from the Table>?ueries dro" down list. %lick the the center of the =orm Wi6ard windows to move all fields from the left side of the window to the right side of the window. 4ou can also use one.

in

to move the fields one by

%lick .-e3t0. *elect the layout that you "refer to use for your form. The default one is %olumnar. %hoosing different o"tion will give you the "review of different layout.

%lick Next. *elect the style you "refer from the subsequent window. %hoosing different

o"tions will give you the "review of the style.

%lick Next. -ame the form $ncounter. %hoose Modify the Forms Design, then "ress Finish.

4ou should see the form design interface like the image below. 4ou can click on a data entry field to highlight. =eel free to resi6e or move any entry field to accommodate "otential data after you create the datable.

1ress the

button on the left u""er corner to toggle the mode to view form. 4ou

can see all your fields are listed in a column layout. 1lease note the form automatically designed the Arrival7Mode as a dro" down list since we used (ooku" wi6ard in our table design. There is no need to enter any data here yet.

=ollow the same ste" to create another form for the 1ATI$-T table.

@. -ow you have the two forms to enter data into the data tables 1ATI$-T and $-%#&-T$/. 1o"ulate some fictional data into the database through the two forms. 4ou need to "o"ulate the 1ATI$-T table first, then the $-%#&-T$/ table. 1lease note that the M/7-#s in the $-%#&-T$/ table must e3ist in the 1ATI$-T table first. At the bottom of the form 9in 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. $nter three "atients and @ encounters for query "ractice in ne3t ste". 1lease have one encounter with the Arrival7Mode as Walking since we are going to use it in our ne3t ste".

A. ?uery data from the database. -ow you have data in the Access database. 4ou can use query to retrieve the data as you needed. =or e3am"le, you might be interested in listing all "atients who walked into the $/. Microsoft Access uses the method ?uery by $3am"le 9?+$: to visually dis"lay the query.

=irst, you need to click the ?uery ,esign button on the %reate tab to access the ?ueries work s"ace.

%lick Create query in Design ie!. 4ou should be able to see the query design view and the "ho! #a$%e window.

Add two tables to the ?uery ,esign view by highlighting the table and "ress &dd button. %lose the "ho! #a$%e window once you have both tables added. In the first field, choose 1ATI$-T.(-ame. In the second field, choolse 1ATI$-T.=-ame. In the third filed, choose $-%#&-T$/.Arrival7Mode. =or the =ield $-%#&-T$/.Arrival7Mode, enter ' ()*+ into the %riteria cell.

*ave the ?uery as 1atient7Walkin. 1ress the run dro"down list

button on the ?uery ,esign toolbar

to run the query. The result of my query is as follows. 1ress the *?( view from the

1ress the *?( view from the dro"down list to view the *?( code behind the scene.

1ress *?( 'iew to view the *?( code.

#ther than listing the "atients meet the criteria, Microsoft Access can also "erform sim"le calculation. =or e3am"le, you want to count the number of "atients walked in the $/. 4ou can use the ,ount e3"ression in Microsoft Access query to calculate the data.

Add the one more field 1ATI$-T.M/7-# to the query design view. 1ress the button on the query design toolbar to dis"lay the row #ota%.

The total row a""ears

%hange the #ota% cell for the field M/7-# to %ount from the dro" down list.

The total cell is changed from grou" by to count.

-ow run the query again. 4ou can see my "atients walk in the $/ twice.

The query we Bust did is called select query. There are other ty"es of queries available in Microsoft Access. %lick on the but feel free to try those. button on the query design toolbar to view the

choice of other query. It is not required in this session to design other ty"e of queries,

Appendix A Doc!mentation of t"e ED database.

C:\Documents and Settings\Xiaoming Zeng\My Documents\AccessLab.mdb Tab&e: 'NC()NT'* Co#!mns Name 'ncounter./D DateArri a& TimeArri a& Arri a&.Mode Chie3.Com,&aint DateDischarge TimeDischarge DischD0 M*.N( Ty,e Te0t Date1Time Date1Time Te0t Te0t Date1Time Date1Time Te0t Te0t

Thursday, No ember !", #$$% +age: !

Si-e !$ 2 2 "$ "$ 2 2 "$ !$

Tab&e: +AT/'NT

Co#!mns Name +atient./D LName 4Name D(5 6ender Street.Address A,art.Number City State Zi,code /nsurance Code Ty,e Te0t Te0t Te0t Date1Time Te0t Te0t Te0t Te0t Te0t Te0t Te0t Si-e !$ "$ "$ 2 7 "$ !$ "$ # " !$

You might also like