Epi Info™ User Guide
How To: Use the Codes Field
A Codes field designates the available options on a form based on the user’s response to a question. Based on the value selected from a drop-down list, other field(s) are populated with predetermined values. At least two fields must exist; one which holds the selection code, and another to receive the value of the code. The first field holds the selection code in a drop-down list while subsequent fields are Read Only and are populated based on the values in the code table. The Codes field allows for more efficient data entry by the user. This field type is not supported on Web Survey. The following figure provides an example of how a Codes field appears in Enter (circled in blue) based on the Surveillance form of the Sample project.
Create a New Codes Table
- Open the Codes Field Definition dialog box.
- Enter the Question or Prompt. The text entered in this field will display on the canvas and prompt the user to enter a response.
- Click in the Field Name text box or press the tab key. Epi Info automatically suggests a field name based on the Question or Prompt, however, it is very important that field names be short, intuitive, and usable. The field name is used for data validation in Check Code and when doing analyses. Field names cannot start with a number or contain any spaces or non-alphanumeric characters (except the underscore character “_” is permitted).
- Select the field(s) to be linked from the Select field(s) to be linked section. To select multiple fields, hold down the CTRL key and click each field.
Note: It is best to simplify the field name at this time. Field names cannot be changed after data collection starts.
- Click on the Data Source browse button.
- Click Create New. A spreadsheet opens for you to enter the values for the Codes field and Linked fields..
- The left-most column displays the selection field(s) chosen in the Fields Definition dialog box.
- Each column to the right lists the field(s) to receive the codes based on the value of the selection field.
- Enter the codes for each field.
- Press the Tab key to move to the next field, or to the next row if at the end of a row.
- Click OK to accept the codes for each field.
- Existing tables can also be used to create code tables.
- Click Create New from Existing (takes a copy of the selected table, changes to the original table will not affect the new table) or Use Existing (establishes a connection between the selected table and the new table, any changes made to the original table will modify the new table)
- Select a table from the drop-down list.
- Click OK.
For information on other attributes that may be available, see the topic on Field Attributes.
- Click OK to close the Field Definition dialog box and place the fields in the form.
- To test the code table, open the Enter tool and verify that both fields populate based on the drop-down list selection.
Create Cascading Drop-Down Fields
Cascading Drop-Down fields are essentially two or more Code, Legal Value, or Comment Legal fields linked together in such a way as to filter each subsequent field based on the value selected in prior fields. In the example described below, the drop-down field for State, filters the drop-down field, County, to show only those counties that exist in the selected State. When County is selected, the drop-down field for Hospital is shown with only the hospitals located in the selected county.
In order to create Cascading Drop-Down fields, you need to have a table completed with all values for the linked fields that can be imported into Epi Info™ 7. The Excel spreadsheet shown below, named ‘codeHospital’, is an example of such a table. When importing this table into your Epi Info™ 7 project, the table name must contain the prefix “code”, as in this example, “codeHospital”.
To add Cascading Drop-down fields, complete the following steps:
- Add the first Codes field to the page, but don’t link the field to other fields, yet. You will do this in later steps. For this example, we named the field StateName.
- Add another Codes field to the page. Again, don’t link the field to other fields, yet. In this example, we named the second field County. Repeat this step for all but the last field in your cascading sequence. In this example, we have only three fields to link, so the next field will be our last.
- Add the last field in our cascading sequence. The last field should be a type other than a Codes field, such as Legal Value or Comment Legal. Since no other fields will be linked to this last field, you don’t want to use a Codes field. In our example, we have two Codes fields named ‘StateName’ and ‘County’, and one Legal Value field named ‘Hospital’.
- If using a Legal Value or Comment Legal field for the last field, click the browse button to the right of Data Source. The Set Up Code / Legal Links dialog opens.
- Click Use Existing. The Open Form – Select a Table dialog box opens.
- Select the code table that was imported and click OK. In this example, we selected the codeHospital table.
- Click OK. The Select a field dialog opens showing the columns in the codeHospital table that can be linked.
- Select the appropriate field. Because we are linking the Hospital field, we selected Hospital in this example.
- Click OK on the Select a Field dialog. The Set Up Code / Legal Links data source table shows the values from the Hospital column in table.
- Click OK on the Set Up Code / Legal Links dialog box.
- Click OK on the field definition dialog. The next steps are to link the fields to the remaining Codes fields.
- Open the properties for the first Codes field added above. (Right click the field and select Properties.) Our first field was ‘StateName’ and we want to link this field to the County field so when State is selected, only the corresponding counties are shown in the County field.
- In the Select Fields to be Linked box, select the field you want to be filtered. Since, in our example, we want the County field to be filtered based on the selection made for State Name, we should select County here.
- Click the Browse button to the right of Data Source. The Codes dialog opens.
- Click Use Existing. The Select a Table dialog box opens.
- Select the same code table used to link the last field. In our example, codeHospital is the code table we are using.
- Click Link. The Match Fields dialog box opens. This is where we match the fields in our cascading sequence to the columns in the code table.
- Select the column to be linked to the first Codes field. Since our first field is State, we selected State.
- In the Link Associated Fields group, select the Form Field to be linked. For our example we want County to be linked to State, so we selected County.
- In the Table Fields drop-down, select the corresponding column in the code table.
- Click Link. The association to the linked field appears in the Linked Fields box.
- Click OK to close the Match Fields dialog.
- Repeat the steps 12 through 22 for each remaining Codes field in the cascading sequence. For each, specify the next field in the cascading sequence and link it to the corresponding field in the code table. In our example, County is the only remaining Codes field to be linked and this field will be linked to Hospital.
This completes the process to create a series of cascading drop-down fields. When the form is opened in Enter, the selection made in the first field in the cascading sequence will filter the values shown in the next field in the sequence. In our example, when Florida is selected for State Name, the list shown for County only includes the values Alchua, Baker, Escambia, and Miami-Dade.
The StateName codes field filters the County codes field because of they way they are linked and because Alchua, Baker, Escambia, and Miami-Dade are the only counties on the same rows as Florida in the codeHospital table.
Likewise, when the county Alchua is selected, only the values Alchua-Hosp1 and Alchua-Hosp2 are shown in the Hospital legal values field.