In this article
When designing a Survey, the options available for you to use as the answers to your questions are limited only by your imagination. To simplify the data processing therefore, rather than using the "user-defined" question and answer texts in the database, Authoring allocates codes both to each question and to each answer option. The code used to identify a question is the "Question ID" (go to Question ID for more information), and that used to identify an answer option is termed the "Code". Each Question ID MUST be unique for the survey, and each answer code MUST be unique for a question.
Figure 1 - Examples of codes for the answers for a Single question
For single questions and the items of a grid, the codes are stored in the database as string values. For multi questions the codes are used together with the Question ID as the variable name. For example a multi question q1 with three answer alternatives with the codes 1, 2 and 3 will give the three variables q1_1, q1_2 and q1_3 in the database. The same logic applies for the elements of a grid.
When creating the answers for a question, you can apply codes to the answer options manually by typing the desired codes into the fields in the Code column on the question's Answers tab. If a code is not supplied manually, then in most cases one will be allocated automatically when the question is saved. This automatic code will be equal to the answer's position in the list, starting from 1. However in some cases the codes will not be allocated automatically until the survey is launched (go to Generating Response Databases for more information). Cases where codes will NOT be allocated automatically include:
- Answer lists in the “Scales and Lists” folder because these may be used in different contexts, before or after other elements, and may also contain one or more “Scales and Lists” objects.
- Answer lists that contain a reference to one or more reusable scales or lists, for the same reason as above.
- Answer lists containing a reference to a “Loop Reference” list because the content of these can be dynamic.
Note that in all these cases you can set the codes manually.
Note: When creating codes manually the ampersand character (&) must not be used as this can cause problems with scripting.
Important
If you change the answer list while a survey is running, you MUST ensure that the codes follow the original answers.
Codes can only contain alphanumeric characters, with no white space. The default maximum length is 32 characters, though you can change this by typing a value (maximum 50) into the Field Width field in the question's Properties sheet. Illegal characters will cause the database compilation to abort. A maximum of 50 characters will not be a problem for single questions, however problems will arise during launch if grid and/or multi questions use the full 50-character codes - see the note below.
Note: In the database, the column headers are constructed as a combination of the question id and the code, and are limited to 50 characters. If this limit is exceeded for a header, then an error message will be displayed when you attempt to launch the survey. Care must therefore be taken when allocating codes for grid and multi questions if the code maximum has been increased above its default setting.
Note: When using the Legacy database format (go to Optimized Database Format for more information), the underscore (_) character can be used, though this is not recommended.
Important
For a question that includes a loop reference (go to Linking a Question to a Loop for more information), any non-loop reference answers must be given codes manually. These answers cannot be allocated codes automatically as the loop reference will very likely cause duplicate codes to be generated.
Conflicting Answer Codes
As from Version 18, codes are mandatory for all the answers in predefined lists. If you do not add codes manually when you create the list then consecutive numerical codes (e.g. 1, 2, 3, 4 etc.) will be added automatically to the list when it is saved. If the predefined list is later added to another list that contains additional answers then the codes used by the two lists may conflict. In this event a message will be displayed and you will be given the opportunity to resolve the conflict.
For example:
You have created a reusable list that uses the answer codes 1,2,3 and 4 - .
Figure 2 - The codes in the reusable list
You later use this list in a question along with other answers - .
Figure 3 - The answer codes in the question along with the reusable list
When you attempt to save the list, the codes will be checked and the duplicate codes will be detected and a message is displayed - .
Figure 4 - The duplicate code message
You can choose to ignore the conflicting codes at this time. Note however that while the conflict exists you will not be able to launch the survey; the launch will fail with an error message warning you of these conflicting codes.
Click Review duplicates to open a grid view showing the conflicting codes - .
Figure 5 - Resolving the conflict in the grid view
In the grid view you can now edit the codes in the question and/or the reusable list as appropriate to ensure they no longer conflict. Bear in mind that if the reusable list has been used in other questions then you will not want to create conflicts in those other questions - it may well be easier to edit the codes in the question rather than the reusable list.