Microsoft Access Lab

Embed Size (px)

Citation preview

  • 8/13/2019 Microsoft Access Lab

    1/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.

  • 8/13/2019 Microsoft Access Lab

    2/18

    ). (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

    $/

  • 8/13/2019 Microsoft Access Lab

    3/18

    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 #.

    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.

  • 8/13/2019 Microsoft Access Lab

    4/18

    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 ofeach field.

    Use Lookup Wizardto 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 Ambulance02 Patient Transport Service03 Public Transport

    04 Private Transport05 Waling0! Police Transport0" 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. ee" the data ty"e as Auto-umber is #.

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

  • 8/13/2019 Microsoft Access Lab

    5/18

    Two new tables

    here.

  • 8/13/2019 Microsoft Access Lab

    6/18

    ;. %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.

  • 8/13/2019 Microsoft Access Lab

    7/18

    ?ueries dro" down list. %lick the in

    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 to move the fields one by

    one.

  • 8/13/2019 Microsoft Access Lab

    8/18

    %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

  • 8/13/2019 Microsoft Access Lab

    9/18

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

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

    Finish.

  • 8/13/2019 Microsoft Access Lab

    10/18

    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. 4oucan 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.

  • 8/13/2019 Microsoft Access Lab

    11/18

    =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".

  • 8/13/2019 Microsoft Access Lab

    12/18

    . ?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$%ewindow.

  • 8/13/2019 Microsoft Access Lab

    13/18

    Add two tables to the ?uery esign view by highlighting the table and "ress &dd

    button. %lose the "ho! #a$%ewindow 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.

  • 8/13/2019 Microsoft Access Lab

    14/18

    *ave the ?uery as 1atient7Walkin. 1ress the run button on the ?uery esign toolbar

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

    dro"down list

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

  • 8/13/2019 Microsoft Access Lab

    15/18

    #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 ,ounte3"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

    1ress *?( 'iew

    to view the *?(

    code.

  • 8/13/2019 Microsoft Access Lab

    16/18

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

    -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 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,

    but feel free to try those.

    The total cell is

    changed from

    grou" by to

    count.

  • 8/13/2019 Microsoft Access Lab

    17/18

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

    C:\Documents and Settings\Xiaoming Zeng\My Documents\AccessLab.mdb Thursday, Noember !", #$$%

    Tab&e: 'NC()NT'* +age: !

    Co#!mns

    Name Tye Si-e

    'ncounter/D Te0t !$

    DateArria& Date1Time 2

    TimeArria& Date1Time 2

    Arria&Mode Te0t "$

    Chie3Com&aint Te0t "$

    DateDischarge Date1Time 2

    TimeDischarge Date1Time 2

    DischD0 Te0t "$

    M*N( Te0t !$

  • 8/13/2019 Microsoft Access Lab

    18/18

    Tab&e: +AT/'NT

    Co#!mns

    Name Tye Si-e

    +atient/D Te0t !$

    LName Te0t "$

    4Name Te0t "$

    D(5 Date1Time 2

    6ender Te0t 7

    StreetAddress Te0t "$

    AartNumber Te0t !$

    City Te0t "$

    State Te0t #

    Zicode Te0t "

    /nsurance Code Te0t !$