Working With Field Codes

 

A No-Macro Macrobutton

 

Two of Word's field codes, Ask and Fill-in, create prompt dialogs for text entry. Both create small input dialogs, but Fill-in responses appear in one position in the document, and Ask data can be used in multiple places in the document. They're both useful for creating forms and legal contracts, for example.

To create a Fill-in field, click where you want the data ultimately to appear and choose Insert | Field. From the Categories list, choose Mail Merge, and from the Field names list, choose Fill-in. In Word 2002, click the Field Codes button. Complete the text area so it looks like this:

FILLIN "What is your name?"

Click OK. When you see the prompt dialog box appear, click OK to accept it. For each entry you expect, create one Fill-in field in the place that the data will appear. When you're done, save the document as a template using File | Save As, and from the Save as type list, choose Document Template (*.dot). Close the document. Whenever you create a document based on this template, you'll be prompted to enter the data. Once you enter the data, click OK to move to the next input dialog.

The Ask field lets you request data and then place it in one or more places in the document. Unlike Fill-in fields, however, Ask fields aren't automatically updated when you create a document based on a template that contains them. Instead, you must update the fields manually, as we'll discuss later. When you create an Ask field, you specify a bookmark name under which to store the data, and then you create references to the bookmark text wherever that data should appear in the document.

Here's how to create an Ask field and place the resulting text in two places in a document. Begin by choosing Insert | Field. From the Field names list, choose Ask. In Word 2002, click the Field Codes button. Complete the text area so it looks like this:

ASK UserName "Type your name" \d "Your name"

Click OK. A prompt dialog will open; click OK to accept it. To create the fields for displaying the text, click in the first position that the name should appear. Choose Insert | Field. From the Categories list, choose Links and References, and from the Field codes list, choose Ref. In Word 2002, click the Field Codes button. Complete the text area like so: REF UserName. This creates a cross-reference to the bookmark called UserName, which is the bookmark name you created in the Ask field.

In the document, you'll see Your name appear where you placed the Ref field. Repeat this process to add another Ref field where you want the data to appear a second time. When you're done, save the document either as a regular file or as a template.

To test the field, open the file (or create a document based on the template) and update the field codes by choosing Edit | Select All (or pressing Ctrl-A), then press F9. You'll be prompted for your name, and it will then appear in both places in the document.

You can request multiple pieces of text by creating a different Ask field code for each and allocating a different bookmark name to each. You can also automate field-code updating by recording these steps as a macro stored in the file. If you name the macro AutoOpen, it will run whenever the file is opened.

As you can see, you can use Word's field codes to help automate many day-to-day tasks, and the codes are a lot more useful than Microsoft's documentation indicates.

Working With Field Codes

Creating a Custom Select List

The AUTOTEXTLIST field code lets you create a drop-down list of AutoText entries. Users select an item on the list to insert the item into the document. Type the entries you want for your drop-down list (single lines or even paragraphs) in a new document. Select them all, and create a new named style for them by typing a name in the Style box on the Formatting toolbar. We'll assume you've typed a list of companies and given it the style name CompanyList.

One at a time, select each entry and set it as an AutoText entry by choosing Insert | AutoText | New. Type the name that will identify this entry in the list and click OK. When you're done, you can delete the entries or discard the document. When you select words or phrases as entries, don't include the trailing paragraph marker.

To create the AutoTextList to display your entries, choose Insert | Field. From the Categories list, choose Links and References, and from the Field names list, choose AutoTextList. Click the Field Codes button in Word 2002. Complete the text area so it looks like this:

AUTOTEXTLIST "Company list" \s "CompanyList" \t "Right-click to select a company"

The first part of the command is the text that will appear in the document. The part after the \s switch is the name of the style you created. The part after the \t switch is ToolTip text that appears when you hold your mouse over the field code.

Note that once you type the first few letters of a designated AutoText item, the full text will pop up in a floating tip. Pressing Enter will fill in the whole thing.

Click OK to continue and save the document before testing it. Test the ToolTip text by holding your mouse pointer over the words Company List, then right-clicking the field code and choosing an entry from the list.

There are a couple of issues to watch out for, however. First, any feature that displays a right-click menu will override this list, so, for example, make sure Track Changes is turned off before you insert Company List. Second, right-clicking the inserted name to access the AutoText list won't work for a name marked as a spelling error. Right-clicking this word will display the spelling menu.

You can use this AutoTextList field code for selectable lists in document templates, too. Create your list separately, then save the AutoTextList field code itself as an AutoText entry. You can insert the text anywhere you need it.

Prompting for Data Entry

Two of Word's field codes, Ask and Fill-in, create prompt dialogs for text entry. Both create small input dialogs, but Fill-in responses appear in one position in the document, and Ask data can be used in multiple places in the document. They're both useful for creating forms and legal contracts, for example.

To create a Fill-in field, click where you want the data ultimately to appear and choose Insert | Field. From the Categories list, choose Mail Merge, and from the Field names list, choose Fill-in. In Word 2002, click the Field Codes button. Complete the text area so it looks like this:

FILLIN "What is your name?"

Click OK. When you see the prompt dialog box appear, click OK to accept it. For each entry you expect, create one Fill-in field in the place that the data will appear. When you're done, save the document as a template using File | Save As, and from the Save as type list, choose Document Template (*.dot). Close the document. Whenever you create a document based on this template, you'll be prompted to enter the data. Once you enter the data, click OK to move to the next input dialog.

The Ask field lets you request data and then place it in one or more places in the document. Unlike Fill-in fields, however, Ask fields aren't automatically updated when you create a document based on a template that contains them. Instead, you must update the fields manually, as we'll discuss later. When you create an Ask field, you specify a bookmark name under which to store the data, and then you create references to the bookmark text wherever that data should appear in the document.

Here's how to create an Ask field and place the resulting text in two places in a document. Begin by choosing Insert | Field. From the Field names list, choose Ask. In Word 2002, click the Field Codes button. Complete the text area so it looks like this:

ASK UserName "Type your name" \d "Your name"

Click OK. A prompt dialog will open; click OK to accept it. To create the fields for displaying the text, click in the first position that the name should appear. Choose Insert | Field. From the Categories list, choose Links and References, and from the Field codes list, choose Ref. In Word 2002, click the Field Codes button. Complete the text area like so: REF UserName. This creates a cross-reference to the bookmark called UserName, which is the bookmark name you created in the Ask field.

In the document, you'll see Your name appear where you placed the Ref field. Repeat this process to add another Ref field where you want the data to appear a second time. When you're done, save the document either as a regular file or as a template.

To test the field, open the file (or create a document based on the template) and update the field codes by choosing Edit | Select All (or pressing Ctrl-A), then press F9. You'll be prompted for your name, and it will then appear in both places in the document.

You can request multiple pieces of text by creating a different Ask field code for each and allocating a different bookmark name to each. You can also automate field-code updating by recording these steps as a macro stored in the file. If you name the macro AutoOpen, it will run whenever the file is opened.

As you can see, you can use Word's field codes to help automate many day-to-day tasks, and the codes are a lot more useful than Microsoft's documentation indicates.

Online Extra

 

If you're working in Microsoft Word 97 or 2000 and you see two prompts inserted when using Ask or FILLIN fields, these Knowledge Base articles may help:

  Word 97: FILLIN Field Prompts Twice (Q164547).

  Word 2000: Two Prompts When Inserting AutoText Entry with ASK or FILLIN Field (Q238978).

You'll find a wealth of useful information for using Word fields here: http://support.microsoft.com/support/word/usage/fields/default.asp

Lastly, if you see a message telling you that the macros in your project are disabled, you must change your macro security level. Choose Tools | Macro | Security. On the Se-curity Level tab, choose Medium and click OK. Exit and restart Word for the change to take place.