Home > Articles > Home & Office Computing > Microsoft Applications

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

This chapter is from the book

Selecting the Right Field

A big part of using fields successfully in Word is knowing which fields are available and which are most applicable to a particular situation. The following sections explain the types of fields available.

Date and Time Fields

In Chapter 7, “Formatting Documents and Sections,” you learned that you can click Date & Time on the Insert tab to insert a date or time code via a dialog box interface. If you mark the Update Automatically check box in this dialog box, Word inserts a {Date} field rather than the actual date or time. If you toggle the field code on an inserted date (Shift+F9), it might look something like this:

{ Date \@ "M/d/yyyy" }

The main switch for the {Date} field is \@, which is followed by the syntax for the date or time format you want.

The {Date} field has a few other switches, but you’ll probably never use them:

  • \h is for the Hijri/Lunar calendar.
  • \l is used to insert the date with the last format chosen using the Date and Time dialog box.
  • \s is used for the Saka Era calendar.

You might be surprised to find that inserting a time with the Date and Time dialog box does not insert a {Time} field. Instead, it inserts a {Date} field with time-based formatting. For example:

{ Date \@ "HH:mm" }

So, what’s the {Time} field for? It’s basically the same as {Date}, except with fewer options. You can’t specify a certain alternative calendar via switches, for example. Strictly speaking, the {Time} field is redundant. It doesn’t need to exist, except that people expect it to and might not think to use a {Date} field to express a time.

arrow.jpg To learn how to create custom date and time formats, see “Constructing a Custom Date or Time Format,” p. 664.

Besides the {Date} and {Time} fields, there are several other date/time-related fields from which you can choose. All of them pull their information from the file’s properties, not from the PC’s clock/calendar.

  • {CreateDate} displays the file creation date. It never changes, because the document’s creation date never changes.
  • {PrintDate} displays the date on which the document was last printed. It updates itself automatically when you print the document.
  • {SaveDate} displays the date on which the document was last saved. It updates itself automatically when you save the document.
  • {EditTime} displays the total amount of time spent editing the document. It does not update automatically.

Document Information Fields

As you learned in “Inserting a Document Property” in Chapter 7, each document has a set of properties. Some of those properties are editable, such as Author; others are automatically calculated by Word, such as FileSize. You can insert these document properties into the document using the document information fields.

Most of these fields have an obvious one-to-one correlation with a certain property. For example, the {Author} field inserts the author’s name, the {Comments} field inserts any comments that have been placed in the document properties, and so on. The field properties vary depending on the nature of the information being inserted. Fields that insert text have properties for setting text case; fields that insert numbers have properties for choosing a number format. Some fields also have additional options. For example, in Figure 16.4, the {FileSize} field’s result can be expressed in either kilobytes or megabytes.

Figure 16.4

Figure 16.4. Document information fields insert various document properties.

If you do an item-by-item check of fields versus properties, you will find that not every document property has a corresponding field. The {DocProperty} field helps overcome this problem. It is a generic inserter for whatever document property you specify. Its list of available properties includes every property available for the document (except custom properties).

For example, suppose that you want to insert the company name from the Company property. There is no Company field, so you would use {DocProperty} like so:

{ DocProperty Company }

User Information Fields

These three simple fields pull user information from Word. They are somewhat like the document information fields. However, this data is not stored with the document, but with the logged-in user on the PC:

  • {UserAddress} inserts the user’s address, if set up in the program. To set up an address, choose File, Options, and click Advanced. In the General section, enter the address into the Mailing Address box.
  • {UserInitials} inserts the user’s initials, if set up in the program. To set up initials, choose File, Options, click General, and enter the initials into the Initials box.
  • {UserName} enters the user’s name, if set up in the program. To set up the name, choose File, Options, click General, and enter the name into the User Name box.

Numbering Fields

The numbering fields have one thing in common: They help you automatically number various types of items in your document. Each is automatically updated whenever you add more numbering fields or rearrange existing fields. For example, if you switch the positions of two figure captions, they also switch numbering.

Most of the numbering fields are inserted via Word’s user interface in various contexts, but a few are available only via the Field dialog box. The numbering fields are listed here:

  • {AutoNum} inserts an automatic number. You can specify the formatting you want for it (Arabic, Roman, letters, and so on). Use this to number anything you like. Each {AutoNum} code in the document shows an incremented value.
  • {AutoNumLgl} inserts an automatic number in legal format, with or without a trailing period.
  • {AutoNumOut} inserts an automatic number in outline format.
  • {BarCode} inserts a delivery point bar code based on the text found in a bookmark. Generally, the bookmark points to a ZIP Code field and changes for each mail merge record with the {Set} field.
  • {ListNum} inserts numbering for a list. This is somewhat like {AutoNum}, but rather than there being three separate fields for regular numbers, legal numbers, and outlines, there are field properties that define which type of list to use. The valid values for this property are LegalDefault, NumberDefault, and OutlineDefault. Another difference is that you can set the level in the list, and you can set a start-at value, so you can have some control over the list.
  • {Page} inserts the number of the current page. You most commonly use this in headers and footers, but you can use it anywhere in the document.
  • {RevNum} counts the number of times the document has been saved. Each time it is saved, the {RevNum} counter is incremented.
  • {Section} displays the section number where the field is placed.
  • {SectionPages} displays the total pages in the section where the field is placed.
  • {Seq} inserts an automatic sequence number. This is the field used for figure captions and other automatically numbered items. A bookmark is created to indicate what type of item is being sequenced. For example, to automatically number figures, each figure has a caption like this: Figure {Seq Figure}. Optional switches can be added for formatting—for example, {Seq Figure \? ARABIC}.

Equation and Formula Fields

These math-related fields are mostly covered elsewhere in Word; you will seldom have reason to insert them manually via the Field dialog box. Here’s a quick round-up of them:

  • {=} is a formula field. Do not try to construct its syntax manually; instead, click the Formula button in the Field dialog box and construct the formula via the Formula dialog box.
  • {Advance} offsets the position of the subsequent text by a specified number of points in a specified direction. You might use this to fine-tune the positioning of text on a page when trying to make printed text line up correctly on a preprinted form, for example.
  • {Eq} inserts an equation using the legacy-style Equation Editor (that is, the version from Word 97–2003). Word does not recommend that you construct the syntax manually; click the Equation Editor button in the Field dialog box to open the legacy Equation Editor.
  • {Symbol} inserts a symbol, by character number, from a specified font. If no font is specified, the font assigned to the paragraph where the field resides takes precedence. Usually, it is preferable to use the Symbol insertion controls on the Insert tab to insert a symbol because you can browse for the desired symbol more easily (that is, you don’t have to know its number).

Index and Table Fields

These fields mark entries for tables of contents, indexes, and tables of authorities; then they generate those items. (The Table in this category’s name refers to tables of contents, tables of authorities, and tables of figures, not to ordinary Word tables.)

These codes are hardly ever inserted manually. A user would use the Table of Contents, Table of Authorities, or Index feature in Word to insert the markers and generate the listings. However, it is useful to know what the various codes mean, in case you see them in documents and need to decide whether to keep or delete them.

These are the codes for indexes:

  • {XE} marks index entries. Various properties and options are available for defining an entry, but these are best created with the Mark Index Entry dialog box (covered in Chapter 19, “Creating Tables of Contents and Indexes”).
  • {Index} generates the index.

For tables of contents, these codes apply:

  • {TC} marks table of contents entries. Usually, tables of contents are generated automatically based on heading levels, but you can use this field to manually mark some text to be included.
  • {TOC} generates the table of contents.

For tables of authorities:

  • {TA} marks the table of authorities entries.
  • {TOA} generates the table of authorities.

For multiple types, {RD} creates an index, table of contents, table of figures, or table of authorities by using multiple documents.

arrow.jpg To create an index, see “Marking Index Entries,” p. 751 and “Generating the Index,” p. 758.

arrow.jpg To create a table of contents, see “Creating a Table of Contents,” p. 731.

arrow.jpg To create a table of authorities, see “Creating Citations and Tables of Authorities,” p. 746.

Link and Reference Fields

This category contains fields that insert linked content from other locations, as well as fields that automatically number pages and footnotes. (Automatic numbering of other items, such as list numbering or figure caption numbering, is handled by fields in the Numbering category, covered previously in this chapter.)

Several of the linking-type fields were covered in Chapter 15, “Copying, Linking, and Embedding Data.” Here’s a quick review of those:

  • {Hyperlink} inserts a hyperlink. Hyperlinks are more commonly inserted via the Hyperlink command on the Insert tab.
  • {Link} inserts an OLE link to an object. OLE links are more commonly inserted via Paste Special or the Insert Object command.
  • {IncludePicture} inserts a non-OLE link to an external picture. Picture links are more commonly inserted via the Insert Picture dialog box by selecting Insert and Link from the Insert button’s drop-down list.
  • {IncludeText} inserts a non-OLE link to an external text file. Text links are more commonly inserted via the Insert Text from File command by selecting Insert as Link from the Insert button’s drop-down list.

The following fields insert numbering codes:

  • {NoteRef} inserts the number of a footnote or endnote. These numbers are automatically updated as content changes in the document. These are normally placed via footnote and endnote insertion.
  • {PageRef} inserts the page number on which the specified bookmark appears. This code is inserted when you create a cross-reference that refers to a page number.

And these fields insert text strings of various types:

  • {Quote} inserts a literal text string that you specify. For example, {Quote "Hello world"} displays the text Hello world.
  • {Ref} inserts text marked by a bookmark. You learned about this one in Chapter 15, in the section “Inserting a Cross-Reference to a Bookmark.”
  • {StyleRef} inserts the text from a paragraph that has the specified style applied. For example, if you have the title of your document set up with a style called DocTitle, the field {StyleRef DocTitle} inserts that title later in the document.

There are also two AutoText-related fields:

  • {AutoText} inserts the specified AutoText entry as an updatable link. This is different from inserting AutoText items from the Building Blocks feature, as in “Working with Building Blocks” in Chapter 2, because the latter inserts an unlinked and non-updatable copy.
  • {AutoTextList} creates a shortcut menu based on AutoText entries in the active template. You specify some placeholder text to appear in the field. When the user right-clicks the field, a pop-up list appears of AutoText entries to choose from to fill in that field.

Document Automation Fields

The document automation fields are used to set up code strings that automate processes in the document. Some programmers prefer to use document automation fields rather than VBA for some basic automation tasks like filling in a form with user information or determining whether one value equals another. Here are a few simple examples.

The {Compare} field compares two values and returns a 1 if the comparison is true or 0 if it is false. It is a programming construct, useful for setting up logical conditions. For example, you might count the number of words in the document with the {NumWords} field and then compare that value to 1000:

{ Compare { NumWords } >= 1000 }

This {Compare} field returns a 1 if the word count is 1000 or above; otherwise, it returns a 0.

The 1 and 0 are all well and good, but it might be nicer to show some meaningful text based on the condition. For that, you need an {If} field. Here’s an {If} field’s syntax:

Expression1 Operator Expression2 TextTrue TextFalse

Suppose, for example, that if {NumWords} is at least 1000, you want to print “OK” in the document; otherwise, you want to print “Need More Words”. Here’s the {If} field to accomplish that:

{ IF { NumWords } >= 1000 "OK" "Need More Words" }

Here are the other available document automation fields:

  • {DocVariable} inserts the value of a VBA Word document variable. (This is not the same as the document’s properties, which you can insert with document information fields covered previously in this chapter.)
  • {GoToButton} inserts a button that, when clicked, jumps the insertion point to a specified bookmarked location.
  • {MacroButton} inserts a button that, when clicked, runs a specified macro.
  • {Print} sends a print instruction to the printer; you can use it to automatically print a document, for example. It is usually combined with some other field, such as {If}, rather than standing alone.

Mail Merge Fields

Chapter 14, “Performing Mail and Data Merges,” covers the Mail Merge feature in Word, which is a robust tool for merging the data from one file or database with a document in another file. Most of the fields involved in mail merging are automatically inserted when you work through the mail merge, or you can insert them using the Rules list on the Mailings tab.

  • {AddressBlock} inserts data pulled from multiple fields to form a standard postal mailing address.
  • {Ask} prompts the user to enter a value to be stored in a bookmark. You can then insert the content of that bookmark anywhere in the document via the {Ref} field.
  • {Compare} compares two values and shows a 1 or 0, depending on whether they match. You learned about this field earlier in the chapter in the “Document Automation Fields” section.
  • {Database} inserts the results of a database query in a Word table.
  • {Fill-in} prompts the user to enter a value and then displays it in the field. This is different from {Ask} in that it does not store the value in a bookmark for later reuse.
  • {GreetingLine} inserts a greeting line in a mail merge document. You can optionally use the \e switch to specify what name to use if the name is blank. For example, you might want something like Dear Valued Customer.
  • {If} prescribes two different actions to take based on the outcome of a logical test. This is like {Compare} except you can specify the output in each situation rather than accepting the default 1 and 0 outputs.
  • {MergeField} inserts a mail merge field. It requires a field name property, like this: {MergeField FirstName}.
  • {MergeRec} numbers each merged record in a mail merge. If a filter excludes any records, they are still numbered, and the numbered records have gaps in the numbering.
  • {MergeSeq} also numbers each merged record in a mail merge, but it does not number records excluded by a filter.
  • {Next} goes to the next record.
  • {NextIf} goes to the next record in a mail merge only if a condition is met.
  • {Set} assigns new text to a bookmark.
  • {SkipIf} skips the next record in a mail merge only if a condition is met. It is the opposite of {NextIf}.
  • + Share This
  • 🔖 Save To Your Account