ms access 2010 example v2.pdf

Upload: wy-teay

Post on 14-Apr-2018

229 views

Category:

Documents


1 download

TRANSCRIPT

  • 7/27/2019 MS Access 2010 example v2.pdf

    1/33

  • 7/27/2019 MS Access 2010 example v2.pdf

    2/33

    MS Access 2010 Example V2.Doc - 2 -

    Checklist for MS Access Database Development

    __a. Create a CODE SHEET: Identify variable (field) names that are associated with the eachquestion on the data collection instrument

    __b. Identify the variables for which drop down lists are desired. Identify the contents of thedrop down lists themselves, too.

    __c. Identify the variables for which skip patterns are desired. Identify the destinations theskip-to variables, also.

    __d. Using a through c above, make a list of the lookup tables, macros and modules that aredesired.

    __e. Create the table that will contain the actual data . For now, these will be empty shells, withno data. Data entry to populate these tables will come later.

    __f. Create the lookup tables that are needed to produce the drop down lists .

    __g. Create the data entry form .

    __h. Modify the design of the data entry form for readability as desired.

    __i. Create the drop down menu utilities. These are the combo boxes .

    __j. Edit your form to ensure data entry will proceed in the correct order.

    __k. Make other formatting changes, as needed, to improve the appearance of your form.

    __l. Create a module with combo box function. Name it module1.

    __m. Create the a macro to maximize the form.

    __n. Create the skip pattern utilities . These are also macros.

    __o. Apply the module, combodrop function, and macros.

  • 7/27/2019 MS Access 2010 example v2.pdf

    3/33

    MS Access 2010 Example V2.Doc - 3 -

    Gail Risk Example

    This example illustrates a form with date, numeric and text responses.

    The completed Microsoft Access database for this example consists of 1 module, 5 tables, 1 formand 5 macros.

    The 5 tables include a main table to store the data ( tblGail) plus 4 additional lookup tables thatprovide drop down data entry choices and associated codes. (These tables are called tblyesno,tblmenop, tblASHKEN, and tblrace ).

    Fig 1: Microsoft Access Database Tables for Gail Risk Data

    __a. Create a CODE SHEET and Coding Manual: Code Sheet: Identify variable (field) names that are associated with the each question onthe data collection instrument.

    Coding Manual : Specify data type and codes or range of values for each field.

    To create a code sheet , annotate a blank copy of the data collection instrument with the variablenames that you have selected. An example of this follows.

    Page 4 shows the original paper data collection form.

    Page 5 is the code sheet , an annotated form showing the variable names associated with eachquestion.

    Pages 6-7 show the coding manual or data dictionary , that spells out details of type of data andcodes for each field to be defined. Have this in hand when you sit down to create your data table.

  • 7/27/2019 MS Access 2010 example v2.pdf

    4/33

    MS Access 2010 Example V2.Doc - 4 -

    Breast Cancer Example Form Original

  • 7/27/2019 MS Access 2010 example v2.pdf

    5/33

    MS Access 2010 Example V2.Doc - 5 -

    Breast Cancer Code Sheet Data Collection Form Annotated with Variable Names

  • 7/27/2019 MS Access 2010 example v2.pdf

    6/33

    MS Access 2010 Example V2.Doc - 6 -

    Coding Manual or Data Dictionary for Gail Risk DataQuestion Variable Name Data Type / Codes DescriptionID IDNUM Numeric, 3-digit

    Range 1 - 999Unique Study Identifier

    BCP Numeric0 No1 Yes9 Unknown

    Patient from ComprehensiveBreast Center

    Q1 DOB Date in MM/DD/YYY Date of BirthQ2 DOP Date in MM/DD/YYY Date of ProcedureQ3 AGE_ATYP Numeric, 2-digit Age at diagnosis of atypiaQ4 MENARCHE Numeric, 2-digit

    99 UnknownAge at Menarche

    Q5 GRAVID Numeric, 2-digit99 Unknown

    Number of times pregnant

    Q6 PARITY Numeric, 2-digit99 Unknown

    Number of live births

    Q7 AGE_FLB Numeric, 2-digit99 Unknown, Notapplicable

    Age at first live birth

    Q8 NUMBIOPS Numeric, 2-digit99 Unknown

    Number of biopsies, includingcurrent one

    Q9 NUM1STDEG Numeric, 2-digit99 Unknown

    Number of 1 st degree femalerelatives with breast cancer

    Q10 NUM2NDDEG Numeric, 2-digit99 Unknown

    Number of 2 nd degreerelatives with breast cancer

    Q11 LMP_MONLMP_DAYLMP_YR

    Numeric 2- or 4-digit99 or 9999 unknown

    Month, Day and Year fields fordate of Last Menstrual Period

    Q12 MENSTAT Numeric, 1-digit1 - Premenopausal2 - Perimenopausal3 - Postmenopausal9 - UNKNOWN

    Menopausal Status

    Q13 BRSTFEED Numeric, 1-digit0 - No1 - Yes9 - UNKNOWN

    History of Breastfeeding

    Q14 HRT Numeric, 1-digit0 - No1 - Yes

    9 - UNKNOWN

    History of HormoneReplacement Therapy

    Q15 NSAID Numeric, 1-digit0 - No1 - Yes9 - UNKNOWN

    Current Non-steroidal Anti-Inflammatory Drug use

  • 7/27/2019 MS Access 2010 example v2.pdf

    7/33

  • 7/27/2019 MS Access 2010 example v2.pdf

    8/33

    MS Access 2010 Example V2.Doc - 8 -

    __b. Identify the variables for which drop down lists are desired. Identify the contents ofthe drop down lists themselves, too.

    That is, identify those fields where you wish to define a drop down list for data entry,and specify the codes and descriptions that will appear on screen in the drop down

    menu.

    Question Variable Name Drop Down Menu Table in AccessQ12 MENSTAT 1 - Premenopausal

    2 - Perimenopausal3 - Postmenopausal9 - UNKNOWN

    Tblmenop

    Q13Q14Q15Q17

    BRSTFEEDHRTNSAIDHISPANIC

    0 - No1 - Yes9 - UNKNOWN

    Tblyesno

    Q16 ASHKENAZI 0 - No1 - Ashkenazi Jewish2 - Dutch3 - Icelandic4 - French Canadian9 - UNKNOWN

    Tblashken

    Q18 RACE 1 - White2 - Black/African Amer3 - Asian4 - Pacific Islander5 - Native Amer.6 - Multiracial7 - Other

    9 - UNKNOWN

    tblrace

    __c. Identify the variables for which skip patterns are desired. Identify the destinations the fields you will skip to, and automatic fill-in values.

    ResponsePrompting Skip

    Skip todestination

    The bypasseditems are:

    The bypassed variablesand assigned values are:

    Q5: Gravid = 0 Q8: NUMBIOPS Q6

    Q7

    PARITY = 0

    AGE_FLB = 99 (unknown)Q6: Parity = 0 Q8: NUMBIOPS Q7 AGE_FLB = 99 (unknown)Q6: Parity = 0 Q14: HRT Q13 BRSTFEED = 0

  • 7/27/2019 MS Access 2010 example v2.pdf

    9/33

    MS Access 2010 Example V2.Doc - 9 -

    __d. Using a through c above, make a list of the lookup tables, macros and modules thatare desired.

    5 Tables are needed:

    1. Table for data (Name: tblGail )

    4 Lookup Tables for drop down menus:

    2. Table for MENSTAT (Name: tblmenop )3. Table for YESNO (Name: tblyesno )4. Table for ASHKENAZI (Name: tblashken )5. Table for RACE (Name: tblrace )

    1 Form is needed:

    Form for data entry (Name: frmGail )

    1 Module is needed:

    Module to implement drop down menu using combo drop function(Name: module1 )

    4 Macros are needed:

    1. Macro to maximize appearance of the form (Name: maximize )2. Macro to skip from Q5 to Q8 (Name: skpQ5toQ8 )3. Macro to skip from Q6 to Q8 (Name: skpQ6toQ8 )4. Macro to skip Q13 altogether (Name: skpQ13frmQ5 )

  • 7/27/2019 MS Access 2010 example v2.pdf

    10/33

    MS Access 2010 Example V2.Doc - 10 -

    __e. Create the table that will contain the actual data . For now, this will be an emptyshell, with no data. Data entry to populate will come later. Note In this example, there is just 1 table that will contain the actual data.

    Steps in Creating an MS Access Table1) Launch Access and open a new data base

    Select File > New At right, click: Blank Database

    Under File Name:Name the file Gail_Risk.accdb At right, click on the folder icon Specify where to store your data base

    Click CREATE . Or, press the ENTER key.

    2) Create your main table which will store your data tblGail CREATE > Table Design

    Fig 1

    3) Using Design View a. Specify Data Type and Field Properties for all your variables .

    (3.1) ID Variable : Enter variable names in the column labeled Field Name starting withthe key variable. The key variable is the linking variable if the database contains several

    tables of data. In this case the key variable is IDNUM.a) Type IDNUM into the Field Name column,b) Tab over to the Data type column and select Number from the listc) Enter the details about the variable in the Field Properties pane at the bottom ofthe screen (Fig 2)

    Fig 2: Field Properties for ID variable

    Note - At Required change No to Yes use required only for ABSOLUTELY required data

  • 7/27/2019 MS Access 2010 example v2.pdf

    11/33

  • 7/27/2019 MS Access 2010 example v2.pdf

    12/33

    MS Access 2010 Example V2.Doc - 12 -

    Summary :For the numeric variables that will hold only codes (BCP,MENSTAT, BRSTFEED, HRT,NSAID, ASHKENAZI, RACE) choose Byte for Field Size in the field properties pane .Byte allows entry of positive integers up to 255.

    For numeric variables requiring a longer field or that will hold numbers you will computewith select Integer as the Field Size.

    Make sure to Select 0 for Decimal Places, and delete the 0 from Default Value. Assign adefault value for fields that will be skipped over assigning the value you want in placewhen the field is skipped.

    For example, when GRAVID=0 (meaning never pregnant) this implies for the fields that willbe skipped:

    PARITY = 0 (no live births)AGE_FLB= 99 (not applicable no age at first live birth)BRSTFEED = 0 (No, never breastfed)

    Tip - The Validation Rule field can be used to avoid data entry errors from invalidresponses. This is illustrated below for LMP_MON (Month of last menstrual period). It isusually paired with Validation Text which contains instructions for data entry if there is anerror (Fig 5).

    The instruction (>=1 And

  • 7/27/2019 MS Access 2010 example v2.pdf

    13/33

  • 7/27/2019 MS Access 2010 example v2.pdf

    14/33

    MS Access 2010 Example V2.Doc - 14 -

    2.7) When finished entering variables, click the Save button.

    Fig 7: Save the Table

    A popup window appears for you to enter the table name. Type tblGail in the box. (Fig 8).Fig 8: Save As

    Click OK

  • 7/27/2019 MS Access 2010 example v2.pdf

    15/33

  • 7/27/2019 MS Access 2010 example v2.pdf

    16/33

    MS Access 2010 Example V2.Doc - 16 -

    __g. Create the data entry form .

    Design Form for Data EntryAt this point you have created a mechanism to store the data the table tblGail is ready to holdthe data. Think of it as an empty spreadsheet that is ready for data entry. The next step is toproduce a form that will enable accurate data entry in a format that mimics the data collectioninstrument.

    This is a short form that only requires a one page data entry screen. Instruments with severalpages might require tabbed forms with a separate tab for each page.

    1) To design your form:CREATE > FORMS > Form Wizard

    Fig 13: Select tblGail from the drop down list of Tables/Queries

    2) The wizard then asks you select the fields for the form. You could select all available fields byclicking the double arrow (>>) to move all fields to the right hand pane, or individually select

    each variable and click the single arrow (>) to move it to the selected fields pane.

    In the figure below Ive selected all the fields except the ones with fixed choices for which Illuse combo boxes with the responses in the tables created in step 3.2. That is: select allexcept BCP, MENSTAT, BRSTFEED, HRT, NSAID, ASHKENAZI, HISPANIC and RACE.

  • 7/27/2019 MS Access 2010 example v2.pdf

    17/33

    MS Access 2010 Example V2.Doc - 17 -

    Fig 14: Choose variables for the form

    Click NEXT.

    3) Select a Columnar layout for the form as shown in Fig 15Fig 15: Select form layout

    Click NEXT.

  • 7/27/2019 MS Access 2010 example v2.pdf

    18/33

    MS Access 2010 Example V2.Doc - 18 -

    4) Name your form by typing frmGail in the title box and select Modify the forms design towork on mimicking the appearance of the data collection instrument.

    Fig 16:Finish the Wizard

    Click FINISH

    __h. Modify the data entry form for readability and to mimic appearance of the paperform.

    1) Position the curser at the top of the Form Footer bar and drag it down to make the form sizebigger (to the 10 mark).

    2) Position the curser at the right edge of the detail page and drag it out to 8.5 using ruler.

    3) Place the curser at the top edge of the detail bar and pull it down to create space for a formheader.

    4) Select the Label tool from the left hand toolbar and draw a box in the Header space abovethe Detail bar. Click inside the box and type BREAST CANCER STUDYNext press Ctrl Enter to go to a new line and type GAIL RISK DATAAt FORMAT > FONT: Select the box. Using the tool bar, select bold and centered.

    5) Rearrange the variable boxes and labels in the detail section to be in the correct places on the

    form.a) Click on the text box for ethnicity and roll the mouse over it until a cross symbol appears,then click and drag it, with its accompanying label to the bottom of the form.

    b) Then, starting below and to the right of the LMP_YR text box, click and drag the mouse untila rectangle forms encompassing the text boxes and labels for LMP_MON, LMP_DAY andLMP_YR. Release the mouse. Those 3 variables are now selected. Again, roll over with themouse until a hand appears and drag all 3 variables to a spot below NUM2NDDEG.

    c) Click outside of the boxes to release them.

  • 7/27/2019 MS Access 2010 example v2.pdf

    19/33

    MS Access 2010 Example V2.Doc - 19 -

    d) Select the text box for LMP_MON by clicking on it.

    e) Roll the mouse to the upper left corner of the text box until it changes to a cross symbol.

    f) Click and drag the text box (without the label) to a position further to the right of the label.

    g) Now select the label box for LMP_MON. Roll the mouse over the right horizontal handle until

    it makes a double headed arrow, and click and drag the mouse to the right to increase thewidth of the box. Type the label Q11. Date of Last Menstrual Period: in the box.

    h) Select the text box for LMP_DAY by clicking on it. Roll the mouse to the upper left corner ofthe text box until it changes to a cross symbol. Click and drag the text box (without thelabel) to a position to the right of the text box for LMP_MON.

    i) Repeat this procedure for the LMP_YR text box, so that it is to the right of LMP_DAY.

    j) Now, using the pointing finger, move the corresponding labels for LMP_DAY and LMP_YRuntil they are below the text boxes.

    k) Click inside the label for LMP_DAY and edit it to read DD. Click inside the label for LMP_YRand edit it to read YYYY.

    l) Use the label tool Aa to draw a new label box below the text box for LMP_MON and type MMinside it.

    m) Also place a new label below Q11 label box and type ENTER 99 OR 9999 IF UNKNOWNin it.

    n) Adjust the sizes of all the boxes to be appropriate to the width of the data that they willcontain.

    Fig 17: Continue Form Design

    4) Header label

    5g) Modified label forLMP_MON

    5h, 5i) Repositioned textboxes

    5m) Newinstruction

    5l) New labelbox for MM

  • 7/27/2019 MS Access 2010 example v2.pdf

    20/33

    MS Access 2010 Example V2.Doc - 20 -

    6) Next rearrange the variables and labels, to match the form, editing the labels and adjusting thewidths.

    7) Add labels with instructions such as ENTER 99 IF UNKNOWN in the appropriate spots.

    8) The form should now look something like Fig 18.

    Fig 18: Modified Form Design

  • 7/27/2019 MS Access 2010 example v2.pdf

    21/33

    MS Access 2010 Example V2.Doc - 21 -

    __i. Create the drop down menu combo boxes.

    To create a combo box for the variable BCP :In this step, you will create a combo box that makes use of the yes/no drop down menu stored

    in the table named tblyesno. You will then associate it with the variable BCP.

    a) Click on the combo box icon from Design -> Control -> combo box .

    b) Position your cursor in the detail area to the right of the ID variable. CLICK. This starts the combo box wizard.

    c) I want the combo box to get the values from another table or query is selected asthe default.

    Fig 19: Combo Box Wizard

    Click NEXT.

    d) Next, select Table: tblyesnoFig 20: Combo Box Wizard Table

    Click NEXT

  • 7/27/2019 MS Access 2010 example v2.pdf

    22/33

  • 7/27/2019 MS Access 2010 example v2.pdf

    23/33

  • 7/27/2019 MS Access 2010 example v2.pdf

    24/33

  • 7/27/2019 MS Access 2010 example v2.pdf

    25/33

  • 7/27/2019 MS Access 2010 example v2.pdf

    26/33

    MS Access 2010 Example V2.Doc - 26 -

    __k. Additional formatting for appearance on the screen .

    i) Starting at the left bottom of the detail area, click and drag a narrow rectangle to select all thelabels and variables on the left of the form.

    ii) At the horizontal tool bar: ARRANGE > SIZE AND ORDERING > ALIGNNow the alignment is neater and more uniform.

    iii) You can make similar changes to align variables and labels Top or Bottom if necessary.

    iv) Click the button at the top to the left of the horizontal ruler bar, to select the entire form a blacksquare appears when the form is selected.

    Fig 26: Select Entire Form

    v) Then click the Design -> property sheet button and change the setting for RecordSelectors to No

    Fig 27: Remove Record Selectors from Form

    iv)

  • 7/27/2019 MS Access 2010 example v2.pdf

    27/33

    MS Access 2010 Example V2.Doc - 27 -

    Other useful features to control data entry

    Your form is almost ready for data entry.

    It is helpful to have the form maximized at the start of data entry, to have the combo boxes youinserted on the form open automatically as the field is entered and to enable automatic skippatterns depending on the responses to questions.

    __l. Create module with combo drop function. Name it module1 .

    Return to the main database window and click Modules on the menu on the left.Click New to open a Microsoft Visual Basic window.

    Fig 28: Module 1 to create combodrop function

    Option Compare Database appears in the window.

    Type in the commands as shown in Fig 28 above.

    Save and close the module. Save it with name module1

  • 7/27/2019 MS Access 2010 example v2.pdf

    28/33

    MS Access 2010 Example V2.Doc - 28 -

    __m. Create the maximize form utility macro.

    In this step, you are writing a macro that tells MS Access to maximize the form at the start of dataentry. It also tells MS Access to go to the ID variable of a new record. See Fig. 29.

    1) Click Macros on the menu on top.2) From the drop down list in the first row of the Action column, select MaximizeWindow 3) From the drop down list in the second row of the Action column

    select GotoRecord 4) From the drop down list in the third row of the Action column select GotoControl 5) In the Control Name box in the Action Arguments pane type IDNUM.6) Click on the Save icon to save the macro. Give it the name Maximize

    Fig 29: Maximize Macro

  • 7/27/2019 MS Access 2010 example v2.pdf

    29/33

  • 7/27/2019 MS Access 2010 example v2.pdf

    30/33

  • 7/27/2019 MS Access 2010 example v2.pdf

    31/33

    MS Access 2010 Example V2.Doc - 31 -

    __o. Apply the modules, combodrop function, and macros .

    Apply the maximize macroa) Return to the forms section of the database, select frmGail and click design to open it in

    design mode if it is not already open.

    b) Select the entire form by clicking on the button at the top to the left of the horizontal rulerbar.

    c) Click on the properties button

    d) Click the Event tab in the properties window

    e) Click in On Open and select the maximize macro from the drop down list

    If the combo function has not already been applied -Apply the combodrop() function that you created in module1

    To do this for the variable BCP:

    a) Click on the BCP combo box The properties window should still be open and now displays the event properties forBCP

    b) Click in the On Got Focus box and type =Combodrop() (Fig 30)

    Fig 30: Apply combodrop() function

    Repeat steps a and b for each of the other combo boxes

    The other combo boxes are MENSTAT, BRSTFEED, HRT, NSAID, ASHKENAZI, HISPANIC and RACE

  • 7/27/2019 MS Access 2010 example v2.pdf

    32/33

  • 7/27/2019 MS Access 2010 example v2.pdf

    33/33

    Now You Can Test the Form!

    Switch to form view Enter data to check that the form works as intendedThe data will be stored in tblGail

    One last note You can configure MS Access to open the form automatically

    MS Access has a feature that allows you to customize its launch, so that it opens to data entryautomatically when access starts.

    1) Click Tools on the horizontal task bar at the top.2) Click Startup 3) From the drop down list under Display Form/Page:, select frmGail as shown in Fig 31 below.

    Fig 31: Automate Data Entry at Startup

    When data entry is complete

    When data entry is complete the form can be closed by clicking the x for the form in theupper right corner below the x for Microsoft Access.