When preparing forms in Word, it would often be desirable to insert a block of text or a complete document based upon the choice offered in a drop-down form field. In the example below, the form field has three choices called Job1, 2 & 3. The actual names of the choices, or the document filenames they represent, doesn't matter a great deal as long as the appropriate changes are made in the conditional fields.
In this first example, note the exit macro UpdateAllFields. This runs as you tab out of the dropdown field, calling the macro code below to force an update of the fields that are used to insert the appropriate document.
The conditional fields are all inserted on the same line, allowed to wrap to the margins, with no spaces between them.
The documents to be inserted in this case are named to match the field choices. Note that the path must be included and you must use double slashes '\\' between the elements of the path.
In the previous example, it doesn't matter whether the document filenames are the same as the words in the dropdown field, as I have shown them, as they are cross referenced by the conditional fields. However, if the document filenames are identical to the entries in the dropdown field, you can simplify the field construction to use a REF field { REF DROPDOWN1 } or simply { DROPDOWN1 } to reproduce the dropdown entry into the INCLUDETEXT path as shown below.
In either case, the document is placed at the location of the conditional field, thus:
Another possibility is to insert the required document using a macro on exit from the field. Here the macro is called DropSelection and the code is shown below:
This macro adds the required document at the end of the form. The result is much the same, except that each time you tab out of the field a copy of the document is added at the end. To replace that document, on tabbing out of the field, it would be necessary to bookmark the target location as shown in the later methods on this page.
On this occasion the documents are called 1.doc, 2.doc & 3.doc and these numbers reflect the order in which the choices are listed in the drop-down list. Thus the First entry will insert 1.doc.
Placing text at a bookmark based on the result of a Check Box or Dropdown form field In more complex forms, it may be desirable to insert variable texts based on the setting of a check box or of the content of a dropdown field (or even a text field), but to have that text placed at a particular bookmarked locations within the document. In the following examples, I have a document with two check boxes and a drop down field. The macros which follow insert a choice of document based on the setting of the first check box and a choice of autotext entries named to match the three possible choices in the dropdown field. Whereas in the last example the three choices were 'First', 'Second' and 'Third', this time I have used 'Yes', 'No' and 'Maybe'.
The check box field inserts either document 'Doc1.doc' or 'Doc2.doc' from the local path 'D:\My Documents\Word Documents'.
For the sake of clarity I have displayed the bookmarks in the document.
The OnExitCB1 macro, run on exit from the check box field inserts the appropriate document in the Check1Result bookmark as shown below. The first document clip shows some random text. The second document clip is identical but the text content is formatted white so that it occupies the same amount of space. You could instead use tables to position texts or simply insert them into an existing string of text.
A similar technique can be used to insert autotext entries if preferred. The use of autotext tends to make things simpler when distributing forms between users, because of the issue of everyone having access to the same documents in the same path.
The second macro example uses autotext to place the variable text.
The macro OnExitDD1 runs from the dropdown field and inserts one of three autotext entries 'ATYes', 'ATNo' or 'ATMaybe' which reflect the three choices 'Yes', 'No' and 'Maybe' previously mentioned. I used the prefix AT for the autotext names to reduce the possibility of confusion with a similar named pre-existing autotext entry. The texts inserted by the entries can be anything that can be held in an autotext entry, which is wide ranging. Here I have used the text displayed in the illustration below.
The OnExitCB1A macro demonstrates how to simply insert text defined in the macro itself, which could be the preferred option where either it won't be necessary for the user to change the wording of the inserted texts over time, or the texts are short. This particular example requires the form to be unlocked and the coding for that is included.
The OnExitCB1B macro below demonstrates yet another means of inserting variable texts into a form. This time I have used a DocVariable here names varCheck1Result to hold the data and a DocVariable field to place the data.
Insert data into a protected form or other document based upon user selection from a list, checkbox etc.