A More Advanced Database Illustration – Access 2010MS Access 2010 Example V2.Doc ... A More...

33
MS Access 2010 Example V2.Doc - 1 - A More Advanced Database Illustration – Access 2010 3.1 Introduction and Checklist This illustration is taken from a form designed for data abstraction from medical records of women diagnosed with breast atypia. The form is intended to collect information to determine risk for developing breast cancer using the “Gail Risk,” a scale that rates risk based upon pregnancy and breastfeeding history along with race, ethnicity and menstrual history. The data abstraction form is shown on page 4. A completed MS Access database for data entry of data collected on this form consists of “tables”, “forms”, “combo boxes”, “macros” and “modules”. The following chart is an orientation to this jargon. MS Access Database Elements Table A table in Access is what we think of as a “spreadsheet” containing the actual data Form You can create an Access form that looks the same or nearly the same as your data collection instrument (the paper form). LookupTable, Combo box, combo drop function: Providing a drop down list for the user to use during data entry is a 3 step process: (1) create a table containing response list and codes – a “lookup” table (2) create a combo box; and (3) create a macro that instructs MS Access to open the list automatically when the field is entered. Module with combo box function: This is an instruction to MS Access that tells MS Access to provide a drop down menu to the user when he/she is doing data entry. Macro to maximize: This is an instruction to MS Access that tells MS Access to maximize the form for the user so that it fills the screen when the form is opened. Macro to observe skip patterns: This is an instruction to MS Access to skip the user to the appropriate “next” query when a skip is desired.

Transcript of A More Advanced Database Illustration – Access 2010MS Access 2010 Example V2.Doc ... A More...

Page 1: A More Advanced Database Illustration – Access 2010MS Access 2010 Example V2.Doc ... A More Advanced Database Illustration – Access 2010 ... Question Variable Name Drop Down Menu

MS Access 2010 Example V2.Doc - 1 -

A More Advanced Database Illustration – Access 2010

3.1 Introduction and Checklist

This illustration is taken from a form designed for data abstraction from medical records of women diagnosed with breast atypia. The form is intended to collect information to determine risk for developing breast cancer using the “Gail Risk,” a scale that rates risk based upon pregnancy and breastfeeding history along with race, ethnicity and menstrual history. The data abstraction form is shown on page 4. A completed MS Access database for data entry of data collected on this form consists of “tables”, “forms”, “combo boxes”, “macros” and “modules”. The following chart is an orientation to this jargon.

MS Access Database Elements Table A table in Access is what we think of as a “spreadsheet” containing the actual data Form You can create an Access form that looks the same or nearly the same as your data collection instrument (the paper form). LookupTable, Combo box, combo drop function: Providing a drop down list for the user to use during data entry is a 3 step process:

(1) create a table containing response list and codes – a “lookup” table (2) create a combo box; and (3) create a macro that instructs MS Access to open the list automatically when the

field is entered. Module with combo box function: This is an instruction to MS Access that tells MS Access to provide a drop down menu to the user when he/she is doing data entry. Macro to maximize: This is an instruction to MS Access that tells MS Access to maximize the form for the user so that it fills the screen when the form is opened. Macro to observe skip patterns: This is an instruction to MS Access to skip the user to the appropriate “next” query when a skip is desired.

Page 2: A More Advanced Database Illustration – Access 2010MS Access 2010 Example V2.Doc ... A More Advanced Database Illustration – Access 2010 ... Question Variable Name Drop Down Menu

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 each

question on the data collection instrument __b. Identify the variables for which drop down lists are desired. Identify the contents of the

drop down lists themselves, too. __c. Identify the variables for which skip patterns are desired. Identify the destinations – the

skip-to variables, also. __d. Using “a” through “c” above, make a list of the lookup tables, macros and modules that are

desired. __e. Create the table that will contain the actual data. For now, these will be empty shells, with

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

Page 3: A More Advanced Database Illustration – Access 2010MS Access 2010 Example V2.Doc ... A More Advanced Database Illustration – Access 2010 ... Question Variable Name Drop Down Menu

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 form and 5 macros. The 5 tables include a main table to store the data (tblGail) plus 4 additional “lookup” tables that provide 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 on the 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 variable names 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 each question. Pages 6-7 show the coding manual or data dictionary, that spells out details of type of data and codes for each field to be defined. Have this in hand when you sit down to create your data table.

Page 4: A More Advanced Database Illustration – Access 2010MS Access 2010 Example V2.Doc ... A More Advanced Database Illustration – Access 2010 ... Question Variable Name Drop Down Menu

MS Access 2010 Example V2.Doc - 4 -

Breast Cancer Example Form – Original

Page 5: A More Advanced Database Illustration – Access 2010MS Access 2010 Example V2.Doc ... A More Advanced Database Illustration – Access 2010 ... Question Variable Name Drop Down Menu

MS Access 2010 Example V2.Doc - 5 -

Breast Cancer Code Sheet – Data Collection Form Annotated with Variable Names

Page 6: A More Advanced Database Illustration – Access 2010MS Access 2010 Example V2.Doc ... A More Advanced Database Illustration – Access 2010 ... Question Variable Name Drop Down Menu

MS Access 2010 Example V2.Doc - 6 -

Coding Manual or Data Dictionary for Gail Risk Data Question Variable Name Data Type / Codes Description

ID IDNUM Numeric, 3-digit Range 1 - 999

Unique Study Identifier

BCP Numeric 0 – No 1 – Yes 9 – Unknown

Patient from Comprehensive Breast Center

Q1 DOB Date in MM/DD/YYY Date of Birth Q2 DOP Date in MM/DD/YYY Date of Procedure Q3 AGE_ATYP Numeric, 2-digit Age at diagnosis of atypia Q4 MENARCHE Numeric, 2-digit

99 – Unknown Age at Menarche

Q5 GRAVID Numeric, 2-digit 99 – Unknown

Number of times pregnant

Q6 PARITY Numeric, 2-digit 99 – Unknown

Number of live births

Q7 AGE_FLB Numeric, 2-digit 99 – Unknown, Not applicable

Age at first live birth

Q8 NUMBIOPS Numeric, 2-digit 99 – Unknown

Number of biopsies, including current one

Q9 NUM1STDEG Numeric, 2-digit 99 – Unknown

Number of 1st degree female relatives with breast cancer

Q10 NUM2NDDEG Numeric, 2-digit 99 – Unknown

Number of 2nd degree relatives with breast cancer

Q11 LMP_MON LMP_DAY LMP_YR

Numeric 2- or 4-digit 99 or 9999 – unknown

Month, Day and Year fields for date of Last Menstrual Period

Q12

MENSTAT Numeric, 1-digit 1 - Premenopausal 2 - Perimenopausal 3 - Postmenopausal 9 - UNKNOWN

Menopausal Status

Q13

BRSTFEED

Numeric, 1-digit 0 - No 1 - Yes 9 - UNKNOWN

History of Breastfeeding

Q14

HRT

Numeric, 1-digit 0 - No 1 - Yes 9 - UNKNOWN

History of Hormone Replacement Therapy

Q15

NSAID

Numeric, 1-digit 0 - No 1 - Yes 9 - UNKNOWN

Current Non-steroidal Anti-Inflammatory Drug use

Page 7: A More Advanced Database Illustration – Access 2010MS Access 2010 Example V2.Doc ... A More Advanced Database Illustration – Access 2010 ... Question Variable Name Drop Down Menu

MS Access 2010 Example V2.Doc - 7 -

Coding Manual or Data Dictionary for Gail Risk Data - continued Question Variable Name Data Type / Codes Description

Q16 ASHKENAZI Numeric, 1-digit 0 - No 1 - Ashkenazi Jewish 2 - Dutch 3 - Icelandic 4 - French Canadian 9 - UNKNOWN

Ethnic Ancestry on list

Q17 HISPANIC Numeric, 1-digit 0 - No 1 - Yes 9 - UNKNOWN

Hispanic or Latina

Q18 RACE Numeric, 1-digit 1 - White 2 - Black/African Amer 3 - Asian 4 - Pacific Islander 5 - Native Amer. 6 - Multiracial 7 - Other 9 - UNKNOWN

Racial Background

Q19 ETHNICITY Text, 20 characters Specify other race/ethnicity

Tips (1) Regarding date variables: When exact dates are known they can be developed as date fields

in the software program eg. Date of Birth and Date of Procedure.

However, if there is a possibility that the full date may not be recorded, such as the day or month part of “Q11. Date of Last Menstrual Period” then the date variable should be defined as 3 separate fields for month (LMP_MON), day (LMP_DAY) and year (LMP_YR). In a later step in data processing these can be combined to create dates and estimate durations as needed.

(2) Regarding “unknown” as response: Some codes are provided on the form, eg. “ENTER 99 IF UNKNOWN” Others are left up to the database designer to determine, eg: “NO=0” “YES=1” “UNKNOWN=9,” or the responses for Q12, Q16 and Q18. Defining these codes is part of the work of designing the codebook and database.

The codes for these responses are stored in the additional tables known as “lookup tables”. The purpose of a lookup table is to match codes to their meaning. This can be almost trivial, as in 0=No, 1=Yes, 9=Unknown, or more complex, as in a system matching billing codes to items billed – which can be an enormous table.

Page 8: A More Advanced Database Illustration – Access 2010MS Access 2010 Example V2.Doc ... A More Advanced Database Illustration – Access 2010 ... Question Variable Name Drop Down Menu

MS Access 2010 Example V2.Doc - 8 -

__b. Identify the variables for which drop down lists are desired. Identify the contents of the 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 Access

Q12 MENSTAT 1 - Premenopausal 2 - Perimenopausal 3 - Postmenopausal 9 - UNKNOWN

Tblmenop

Q13 Q14 Q15 Q17

BRSTFEED HRT NSAID HISPANIC

0 - No 1 - Yes 9 - UNKNOWN

Tblyesno

Q16 ASHKENAZI 0 - No 1 - Ashkenazi Jewish 2 - Dutch 3 - Icelandic 4 - French Canadian 9 - UNKNOWN

Tblashken

Q18 RACE 1 - White 2 - Black/African Amer 3 - Asian 4 - Pacific Islander 5 - Native Amer. 6 - Multiracial 7 - 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.

Response Prompting Skip

“Skip to” destination

The bypassed items are:

The bypassed variables and 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

Page 9: A More Advanced Database Illustration – Access 2010MS Access 2010 Example V2.Doc ... A More Advanced Database Illustration – Access 2010 ... Question Variable Name Drop Down Menu

MS Access 2010 Example V2.Doc - 9 -

__d. Using “a” through “c” above, make a list of the lookup tables, macros and modules that are 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)

Page 10: A More Advanced Database Illustration – Access 2010MS Access 2010 Example V2.Doc ... A More Advanced Database Illustration – Access 2010 ... Question Variable Name Drop Down Menu

MS Access 2010 Example V2.Doc - 10 -

__e. Create the table that will contain the actual data. For now, this will be an empty shell, 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 Table

1) 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 with the “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 list c) Enter the details about the variable in the “Field Properties” pane at the bottom of the screen (Fig 2)

Fig 2: Field Properties for ID variable

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

Page 11: A More Advanced Database Illustration – Access 2010MS Access 2010 Example V2.Doc ... A More Advanced Database Illustration – Access 2010 ... Question Variable Name Drop Down Menu

MS Access 2010 Example V2.Doc - 11 -

d) Choose ‘Long Integer’ for the field size – best for use with the key variable e) Select the key icon on the task bar to indicate that this variable is the primary key

Fig 3: Task bar showing “key” icon

f) Select ‘0’ for decimal places g) Type ‘ID’ for the caption h) Check that the Default value is blank i) Select ‘Yes’ in the ‘Required’ Field j) Type “ID:” as the Caption k) Type “Unique Study ID number” in the Description column

Other variables: Enter details for all the other variables in the table and field properties panes, choosing Date/Time as the field type for DOB and DOP, Text as the field type for ETHNICITY, and Number as the field type for all other variables.

Fig 4: List of all variables with Data Type

Page 12: A More Advanced Database Illustration – Access 2010MS Access 2010 Example V2.Doc ... A More Advanced Database Illustration – Access 2010 ... Question Variable Name Drop Down Menu

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 compute with select “Integer” as the Field Size. Make sure to Select “0” for Decimal Places, and delete the “0” from Default Value. Assign a default value for fields that will be skipped over – assigning the value you want in place when the field is skipped. For example, when GRAVID=0 (meaning never pregnant) this implies for the fields that will be 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 invalid responses. This is illustrated below for LMP_MON (Month of last menstrual period). It is usually paired with “Validation Text” which contains instructions for data entry if there is an error (Fig 5). The instruction (>=1 And <=12) Or =99 specify valid values for the month. If any other value is entered the message “Enter a month between 1 and 12 or 99 if unknown” will appear on screen.

Fig 5: Field Properties panel for variable LMP_MON illustrating Validation Rule

Page 13: A More Advanced Database Illustration – Access 2010MS Access 2010 Example V2.Doc ... A More Advanced Database Illustration – Access 2010 ... Question Variable Name Drop Down Menu

MS Access 2010 Example V2.Doc - 13 -

(3.3) For the date variables DOB and DOP, do the following: At the bottom of your screen, in the panel called “Field Properties” and in the tab GENERAL, choose the following settings: Format: Short date Input mask: 90/90/0000;0;_ Caption: Date of birth or Date of procedure … Required: No Indexed: No IME Mode: No control IME Sentence Mode: None Note - The field properties pane for DOB demonstrates specification of a date/time variable. Here we’ds using “Short Date” to enter dates in MM/DD/YYYY format. The “Input Mask” as shown in Fig 6 provides the format for the data entry – so that there is no need to type the slashes when entering dates – the slashes will be added automatically.

Fig 6: Field Properties pane for a Date/Time variable

(3.4) For the text variable ETHNICITY do the following: Enter a field size large enough to accommodate anticipated responses. Here we’ve selected 20. (3.5) For all the variables except BCP, DOB, DOP, LMP_YR and ETHNICITY do the following: At the bottom of your screen, in the panel called “Field Properties” and in the tab GENERAL, choose the following settings: Field Size: Byte or Integer … Decimal Places: 0 Default value: delete the value 0 that MS Access has provided by default

Page 14: A More Advanced Database Illustration – Access 2010MS Access 2010 Example V2.Doc ... A More Advanced Database Illustration – Access 2010 ... Question Variable Name Drop Down Menu

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

Page 15: A More Advanced Database Illustration – Access 2010MS Access 2010 Example V2.Doc ... A More Advanced Database Illustration – Access 2010 ... Question Variable Name Drop Down Menu

MS Access 2010 Example V2.Doc - 15 -

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

In this step you are doing the first of several steps required in MS Access in order of have drop down menus. In this first step, you are creating the “lookup tables” that MS Access requires. From there, you will create the associated combo boxes.

Recall - The 4 lookup tables that provide responses for the drop down menus will be named tblyesno, tblmenop, tblASHKEN, and tblrace. Each table contains contain 2 fields – a numeric variable that stores the codes, and a text variable that provides the descriptions of the codes. First, create the tables in design mode with the numeric variable containing the codes being the “key” variable. In this case “Byte” is adequate for the field size. The field size for the text variables varies depending on the responses. Table 1 shows the variables and the field sizes for the text variables.

Combo Box tables:

Table Name

Name of Code Variable (*Primary key)

Data Type

Field Size

Name of Description

Variable

Data Type Field Size

1 tblyesno codeyn Number Byte yesno Text 15

2 tblmenop codemenop Number Byte menop Text 15

3 tblASHKEN codeashken Number Byte txtashken Text 20

4 tblrace coderace Number Byte textrace Text 35

Be sure to designate the code variable as key when defining the tables. The code will be used to link the code in the data to the description in the drop down box. Next, switch to datasheet view: Enter data in each table to show the code with corresponding description.

Numeric Code Text Description

Fig 9: tblyesno Fig 10: tblmenop

Fig 11: tblASHKEN Fig 12: tblrace

Page 16: A More Advanced Database Illustration – Access 2010MS Access 2010 Example V2.Doc ... A More Advanced Database Illustration – Access 2010 ... Question Variable Name Drop Down Menu

MS Access 2010 Example V2.Doc - 16 -

__g. Create the data entry form.

Design Form for Data Entry

At this point you have created a mechanism to store the data – the table “tblGail” is ready to hold the data. Think of it as an empty spreadsheet that is “ready” for data entry. The next step is to produce a form that will enable accurate data entry in a format that mimics the data collection instrument. This is a short form that only requires a one page data entry screen. Instruments with several pages 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 by

clicking 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 I’ve selected all the fields except the ones with fixed choices for which I’ll use “combo boxes” with the responses in the tables created in step 3.2. That is: select all except BCP, MENSTAT, BRSTFEED, HRT, NSAID, ASHKENAZI, HISPANIC and RACE.

Page 17: A More Advanced Database Illustration – Access 2010MS Access 2010 Example V2.Doc ... A More Advanced Database Illustration – Access 2010 ... Question Variable Name Drop Down Menu

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 15 Fig 15: Select form layout

Click NEXT.

Page 18: A More Advanced Database Illustration – Access 2010MS Access 2010 Example V2.Doc ... A More Advanced Database Illustration – Access 2010 ... Question Variable Name Drop Down Menu

MS Access 2010 Example V2.Doc - 18 -

4) Name your form by typing “frmGail” in the title box and select “Modify the form’s design” to work 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 paper form.

1) Position the curser at the top of the Form Footer bar and drag it down to make the form size

bigger (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 form header.

4) Select the “Label” tool from the left hand toolbar and draw a box in the Header space above the Detail bar. Click inside the box and type ‘BREAST CANCER STUDY’ Next press Ctrl Enter to go to a new line and type “GAIL RISK DATA” At 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 until a rectangle forms encompassing the text boxes and labels for LMP_MON, LMP_DAY and LMP_YR. Release the mouse. Those 3 variables are now selected. Again, roll over with the mouse until a “hand” appears and drag all 3 variables to a spot below NUM2NDDEG.

c) Click outside of the boxes to release them.

Page 19: A More Advanced Database Illustration – Access 2010MS Access 2010 Example V2.Doc ... A More Advanced Database Illustration – Access 2010 ... Question Variable Name Drop Down Menu

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 the width 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 of the text box until it changes to a “cross symbol”. Click and drag the text box (without the label) 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_YR until 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_YR and 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 MM inside it.

m) Also place a new label below Q11 label box and type “ENTER 99 OR 9999 IF UNKNOWN” in it.

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

Fig 17: Continue Form Design

4) Header label

5g) Modified label for

LMP_MON

5h, 5i) Repositioned text boxes

5m) New instruction

5l) New label box for MM

Page 20: A More Advanced Database Illustration – Access 2010MS Access 2010 Example V2.Doc ... A More Advanced Database Illustration – Access 2010 ... Question Variable Name Drop Down Menu

MS Access 2010 Example V2.Doc - 20 -

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

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

Page 21: A More Advanced Database Illustration – Access 2010MS Access 2010 Example V2.Doc ... A More Advanced Database Illustration – Access 2010 ... Question Variable Name Drop Down Menu

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 as the default.

Fig 19: Combo Box Wizard

Click NEXT.

d) Next, select Table: tblyesno Fig 20: Combo Box Wizard Table

Click NEXT

Page 22: A More Advanced Database Illustration – Access 2010MS Access 2010 Example V2.Doc ... A More Advanced Database Illustration – Access 2010 ... Question Variable Name Drop Down Menu

MS Access 2010 Example V2.Doc - 22 -

e) You will see codeyn and yesno as the available fields. Click the double arrow (>>) to move them both to the Selected Fields list.

Fig 21: Combo Box Wizard Fields

Click Next f) Choose the field codeyn for ascending sort order g) Adjust the width of the text field (yesno) to be as wide as the longest response by double

clicking the right border. Keep “hide key column” checked. Fig 22: Combo Box Wizard Column Width

Click NEXT

Page 23: A More Advanced Database Illustration – Access 2010MS Access 2010 Example V2.Doc ... A More Advanced Database Illustration – Access 2010 ... Question Variable Name Drop Down Menu

MS Access 2010 Example V2.Doc - 23 -

h) Click “Store that value in this field:” and select BCP from the drop down box. In doing this, you are telling MS Access to associate the information in tblyesno with the variable BCP

Fig 23: Choose Variable to be associated with Combo Box

Click NEXT.

i) Type a “label” in the dialogue box “What label would you like for your combo box? This label appear like a caption on the data entry form.

Fig 24: Complete Combo Box Wizard

Click Finish

Page 24: A More Advanced Database Illustration – Access 2010MS Access 2010 Example V2.Doc ... A More Advanced Database Illustration – Access 2010 ... Question Variable Name Drop Down Menu

MS Access 2010 Example V2.Doc - 24 -

To finish up associating the combo box with the field BCP:

j) Under DESIGN > TOOLS: click on “Property Sheet” Choose the tab labeled “All” At the entry “Name ……” type in the field name BCP (Fig 25)

k) Before closing this box, scroll down until you see “List rows ……”. Note – it doesn’t quite

show up in Fig 25 but you’ll see it once you scroll down.. Change the value from 16 to 3. You only want 3 choices (no, yes, unknown) here.

Fig 25: Name the Combo Box

Click on the “X” at the upper right to close the Properties box.

Similarly, create a combo box for each of MENSTAT, BRSTFEED, HRT, NSAID, ASHKENAZI, HISPANIC, and RACE Repeat steps “a” through “k” to create combo boxes for Q12 – Q18 (please refer to the questionnaire), choosing the appropriate table for the responses (tblyesno for BRSTFEED, HRT, NSAID, HISPANIC, etc), naming each combo box to match the variable it represents, and editing the labels to match the form.

Page 25: A More Advanced Database Illustration – Access 2010MS Access 2010 Example V2.Doc ... A More Advanced Database Illustration – Access 2010 ... Question Variable Name Drop Down Menu

MS Access 2010 Example V2.Doc - 25 -

__j. Edit form for correct data entry order.

MS Access allows you to rearrange the order of data entry prompts on the form. Since we added the combo boxes to the form after the other fields, the cursor will move to those late additions after the other fields. Our goal here is to reset the order to match the question order.

To do this: DESIGN > TOOLS > Tab Order ” on the horizontal task bar

Example –

- Select (highlight) the BCP row and move it to the second position under IDNUM.

- Select the ETHNICITY row and move it to the last position. - Make sure the other fields appear in correct order.

Page 26: A More Advanced Database Illustration – Access 2010MS Access 2010 Example V2.Doc ... A More Advanced Database Illustration – Access 2010 ... Question Variable Name Drop Down Menu

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 the labels and variables on the left of the form.

ii) At the horizontal tool bar: ARRANGE > SIZE AND ORDERING > ALIGN Now 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 black

square appears when the form is “selected”.

Fig 26: Select Entire Form

v) Then click the “Design -> property sheet” button and change the setting for “Record

Selectors” to “No” Fig 27: Remove Record Selectors from Form

iv)

Page 27: A More Advanced Database Illustration – Access 2010MS Access 2010 Example V2.Doc ... A More Advanced Database Illustration – Access 2010 ... Question Variable Name Drop Down Menu

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 you inserted on the form open automatically as the field is entered and to enable automatic skip patterns 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

Page 28: A More Advanced Database Illustration – Access 2010MS Access 2010 Example V2.Doc ... A More Advanced Database Illustration – Access 2010 ... Question Variable Name Drop Down Menu

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 data entry. 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

Page 29: A More Advanced Database Illustration – Access 2010MS Access 2010 Example V2.Doc ... A More Advanced Database Illustration – Access 2010 ... Question Variable Name Drop Down Menu

MS Access 2010 Example V2.Doc - 29 -

__n. Create skip pattern utility macros. Recall that we want the following skip patterns. Response Prompting Skip

“Skip to” destination

The bypassed items are:

The bypassed variables are:

Q5: Gravid = 0 Q8: NUMBIOPS Q6 PARITY = 0 Q6: Parity = 0 Q8: NUMBIOPS Q7 AGE_FLB = 99 Q6: Parity = 0 Q14: HRT Q13 BRSTFEED = 99 Recall, also that we have already decided upon names for these macros:

Macro to skip from Q5 to Q8 (Name: skptoQ8) Macro to skip Q13 altogether (Name: skpQ13)

These are examples of macros that are executed, depending on a condition. In this example, one condition that prompts execution of a macro is Q5 gravid=0. The other is Q6: parity=0. To create macro skpQ5toQ8 which will skip the user to Q8 if they answer “0” to Q5 a) From the toolbar: CREATE > MACRO & CODE > “macro” . b) Select DESIGN > SHOW/HIDE > SHOW ALL ACTIONS c) Locate drop down menu at top of screen. From this drop down: Select IF d) In the box IF: type the following in f the condition for the skip pattern: “[GRAVID]=0” Important – Be sure that you have square brackets around the variable name. e) In the next drop down box: select “GO TO CONTROL” f) In the box labeled “Control Name”, type the destination of the skip pattern: “NUMBIOPS” g) Save the macro with the name skpQ5toQ8 In a similar fashion – Create the macro skip skipQ6toQ8 which will skip the user to Q8 if they answer “0” to Q6. The condition to type into the box next to “If” here will be “[PARITY]=0”

Page 30: A More Advanced Database Illustration – Access 2010MS Access 2010 Example V2.Doc ... A More Advanced Database Illustration – Access 2010 ... Question Variable Name Drop Down Menu

MS Access 2010 Example V2.Doc - 30 -

To create macro skpQ13frmQ5 which will skip the user from Q12 to Q14 if they answer “0” to Q5 a) From the toolbar: CREATE > MACRO & CODE > “macro” . b) Select DESIGN > SHOW/HIDE > SHOW ALL ACTIONS c) Locate drop down menu at top of screen. From this drop down: Select IF d) In the box IF: type the following in f the condition for the skip pattern: “[GRAVID]=0” e) In the next drop down box: again select IF f) In the box that appears next to IF: type the name of the variable that the skip pattern will begin

at: “MENSTAT”

g) In the next drop down box: select “GO TO CONTROL” h) In the box labeled “Control Name”, type the destination of the skip pattern: “HRT” i) Save the macro with the name skpQ13frmQ5 In a similar fashion – Create the macro skip skipQ13frmQ6 which will skip the user from Q12 to Q14 if they answer “0” to Q6. The condition to type into the box next to the first “If” here will be “[PARITY]=0”

Page 31: A More Advanced Database Illustration – Access 2010MS Access 2010 Example V2.Doc ... A More Advanced Database Illustration – Access 2010 ... Question Variable Name Drop Down Menu

MS Access 2010 Example V2.Doc - 31 -

__o. Apply the modules, combodrop function, and macros. Apply the maximize macro a) 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 ruler bar.

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 for BCP

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

Page 32: A More Advanced Database Illustration – Access 2010MS Access 2010 Example V2.Doc ... A More Advanced Database Illustration – Access 2010 ... Question Variable Name Drop Down Menu

MS Access 2010 Example V2.Doc - 32 -

Apply the macros to control skip patterns For the skip pattern executed by skpQ5toQ8 a) Click on the text box for GRAVID (Q5) b) In properties, click in the “On Exit” box and select the macro skpQ5toQ8

from the drop down list For the skip pattern executed by skpQ6toQ8 a) Click on the text box for PARITY b) Click in the “On Exit” box and select the macro skpQ6toQ8 from the drop down list For the skip pattern executed by skpQ13frmQ5 a) Click on the text box for MENSTAT b) Click in the “On Exit” box and select the macro skpQ13frmQ5 from the drop down list

For the skip pattern executed by skpQ13frmQ6 a) Click on the text box for MENSTAT b) Click in the “On Exit” box and select the macro skpQ13frmQ6 from the drop down list

Save the form!

Page 33: A More Advanced Database Illustration – Access 2010MS Access 2010 Example V2.Doc ... A More Advanced Database Illustration – Access 2010 ... Question Variable Name Drop Down Menu

MS Access 2010 Example V2.Doc - 33 -

Now You Can Test the Form!

Switch to form view Enter data to check that the form works as intended The 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 entry automatically 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 the upper right corner below the x for Microsoft Access.