Home > Articles > Home & Office Computing > Microsoft Applications

  • Print
  • + Share This
This chapter is from the book

Inserting Fields

You can insert many fields via the regular Word user interface, as listed in Table 16.1. However, you can also insert a field using the Insert Field command, a more direct route that provides access to more of the field’s optional switches and parameters.

To insert a field, follow these steps:

  1. Position the insertion point where you want the field to be inserted.
  2. On the Insert tab, click Explore Quick Parts and then click Field. The Field dialog box opens.
  3. (Optional) On the Categories list, select a category to narrow the list of field names.
  4. On the Field Names list, click the desired field name. Lists and check boxes appear for the available options for that field. For example, in Figure 16.1, the options for the Date field are shown.

    Figure 16.1

    Figure 16.1 Insert a field from the Field dialog box.

  5. Select any options as needed, and then click OK.

Specifying Field Properties and Options

As you insert a field (as in the preceding section), the Field dialog box prompts you to select the properties and options you want. Field properties are settings from which you must make a selection (or accept the default). For example, in Figure 16.1, the date format is a property. If you do not choose one, Word uses a default property. Field options are optional parameters; to omit them, simply leave their check boxes blank.

If you are interested in the codes behind these user-friendly dialog box controls, click the Field Codes button in the Field dialog box to display the Field Codes text box. It shows the code that Word inserts for the properties and options selected so far (see Figure 16.2).

Figure 16.2

Figure 16.2 View the codes behind the properties and options you have selected.

To delve even further into the field’s coding, click the Options button to display the Field Options dialog box. Switches that apply to multiple fields are shown on the General Switches tab (Figure 16.3) and switches specific to the selected field appear on the Field Specific Switches tab (which you will see later in this chapter, in Figure 16.4). To add one of them, select it and click Add to Field.

Figure 16.3

Figure 16.3 Work directly with the field’s optional switches and properties in the Field Options dialog box.

Figure 16.4

Figure 16.4 Document information fields insert various document properties.

Manually Typing Field Codes

If you know exactly what you want in terms of field codes, you might find it easier and quicker to simply type them into your document.

Field codes are bracketed with curly braces, like this: {Date}. However, you can’t manually type the curly braces, because Word won’t recognize the code as a field. Instead, you must press Ctrl+F9 to get the ball rolling.

Ctrl+F9 inserts a blank set of curly braces in a shaded field box. From there, you can type the desired field name and any switches or other syntax needed. (If you don’t know the exact syntax you need, it’s better to go with the dialog box method of field insertion.)

Here are some tips for getting the syntax right:

  • Field names are not case sensitive.
  • If a property or argument contains spaces, you must enclose it in quotation marks. For example, {Username "John Doe"} would be correct. {Username John} would also work because John does not have spaces in it, but { Username John Doe } would be incorrect.
  • If you need a real quotation mark, use "\".
  • If you’re specifying a path, use double backslashes rather than single—for example, { IncludeText C:\\Docs\\Myfile.doc }. This is necessary because single backslashes indicate switches and special codes.
  • Leave one space between the field name and each property or switch.
  • Leave one space between the backslash (\) in the switch and its parameters.
  • Leave one blank space to the right of the left bracket and to the left of the right bracket.

Toggling Between Data and Field Code Views

By default, a field displays its result in the document rather than its code. (Exception: Fields that do not generate results, such as bookmarks and index markers, do not display at all by default.)

To toggle between displaying the field result and the field code, do either of the following:

  • Select the field and press Shift+F9.
  • Right-click the field and choose Toggle Field Codes.

Note that this toggles only the selected field. To toggle more than one field at once, select a contiguous area of the document that includes multiple fields and press Shift+F9. To toggle all the field codes in the entire document at once, press Alt+F9, or select the entire document (Ctrl+A) before pressing Shift+F9.

Field codes in the document appear just like they do in the Field dialog box (refer to Figure 16.2). They appear with a gray background, which helps you remember they are fields, but that gray background does not print and does not appear in Print Preview or Read mode.

Editing Field Code Strings

When a field code string is displayed in the document (Shift+F9), you can edit it manually just like any other text. The trick is knowing what to type. Many fields have fairly complex code strings with various properties and options.

Most people aren’t able to remember all the syntax rules for each field type, of course, so Word provides an easier way to edit a field code string: Right-click the field code and choose Edit Field. The Field dialog box reappears, as in Figure 16.1, and you can make any changes needed via a friendly dialog box interface.

Nesting Fields

When you’re using fields that require input, such as the logical condition ones like {Compare} and {If}, you might want that input to come from other fields. To manage this, you can nest one field inside another.

For example, you might want to test whether today is a certain day of the week. If it is Friday, this message should appear: “Time cards are due today by 5:00 p.m.” Otherwise, this message should appear: “Time cards are due on Fridays by 5:00 p.m.” Here’s the complete syntax for that:

{ If { Date \@ "dddd" } = "Friday" "Time cards are due today by 5:00 p.m." "Time
cards are due on Fridays by 5:00 p.m." }

The main thing to remember when nesting fields is that you can’t type the braces for the nested fields; you must insert the braces with Ctrl+F9. Let’s go over the general process.

First, you would start the outer field:

  1. Press Ctrl+F9 to insert a new blank set of braces.
  2. Type the desired field name and then any portion of the field’s properties or switches that should come before the nested field.
  3. Press Ctrl+F9 to insert another new blank set of braces, and in the new set, type the field to be nested.
  4. Click to move the insertion point to the right of the closing bracket for the nested field, and continue typing the outer field.
  5. Press F9 to update the field and display its result.

Here’s another example. The {Set} field creates a bookmark. It requires two pieces of information: the bookmark name and the text that should be placed within it. So, for example, if you want to create a bookmark called CompanyName and set its value to Microsoft, the field should read as follows:

{ Set CompanyName "Microsoft" }

That’s fine, but what if the company name changes? You can instead use the {FillIn} field to ask the user to specify the company name:

{ Set CompanyName { FillIn "Enter the company name" } }

Now suppose that you want to enter that company’s name in the Title field of the document’s properties. Create another nested set of fields like this:

{ Title { Ref CompanyName } }
  • + Share This
  • 🔖 Save To Your Account