CHAPTER 23

Automating Document Content with Fields

IN THIS CHAPTER

  • Understanding field codes
  • Inserting fields with the Field dialog box
  • Customizing fields
  • Using field syntax and switches
  • Reviewing available fields by category

This book has touched on fields several times, but only in relation to their role in other Word features. You've seen fields used to insert dates and page numbers, to number equations, and a few other things. So far, however, the book hasn't delved into fields and how to use them to automate document content.

A number of tasks that required fields in Word 2003 and earlier can now be performed more efficiently and elegantly with content controls (contained in the Controls section of the Developer tab; see Chapter 24, “Creating Custom Forms”). If you work with complex documents in compatibility mode, you are much more likely to encounter fields than when working in the .docx format.

Moreover, a number of linking tasks that require the use of fields in a compatibility-mode document can be performed in ways that are more robust (harder to break) in the XML-based Word .docx format, so when you insert links you're less likely to see field codes than before. Instead, much is done behind the scenes with XML technology.

Yet some Word 2013 features—dates, page numbers, mail merge, tables of contents, indexes, and some others—still do rely on fields. This book covers a number of the field-dependent features elsewhere. This chapter's mission is not to redundantly cover those other features. Rather, it is to provide a strong background and foundation that helps you thoroughly understand the relationship between fields and specific features, and how you can insert fields manually to make a document easier to use and update. Equipped with this information, you'll be in a solid position to take advantage of the power of fields when needed, to choose between legacy and newer approaches when the option presents itself, and to deal with the occasional challenges that inevitably creep in.

And Field Codes Are … ?

Field codes are special sets of instructions in Word documents. They sometimes tell Word to display the current date, the number of pages in a document or a document section, an index, a table of contents, the contents of all or of part of a linked document, or the file name and folder where the current document is stored. Field instructions (called switches) also tell Word how to display the specified information.

Word enables you to update most fields. When the source information for a field changes, you can update the field so it displays the latest information. This enables you to turn documents into more dynamic information containers, rather than static documents that always contain the same information. To update a field, click it and press F9. Other update methods are available as well, as you will see later in this chapter.

You can format fields just like regular text. You can apply font, paragraph, and other formatting to field results so that they blend in with your document. Sometimes you don't even know information is in a field code until you look more carefully. As you will see, however, for the person working on the document, knowing that something is a field is critically important.

Many fields can be unlinked easily and turned into permanent content that doesn't change. This enables you to create a snapshot, rather than dynamic content. This means that you can use the convenience of a field to insert today's date, but then lock that date in so that when you look at a letter years from now it will have the original date, rather than some date in 2018. That way you'll know when the letter was written, but if you repurpose a copy of that letter, you can unlock the date field so it can be updated.

Mastering Field Basics

As suggested earlier, sometimes fields are inserted automatically as part of some other process, such that you aren't even specifically aware that fields are involved. For example, in the Insert tab's Text group, click the Insert Date and Time field button, as shown in Figure 23.1.

FIGURE 23.1

Some features such as Insert Date and Time insert a field.

image

In response, the Date and Time dialog box springs to life. If you choose a format and click OK, you'll get just the date and/or time in the format selected, and not a field. If you enable the Update automatically option indicated in Figure 23.2 before clicking OK, Word instead inserts a DATE field.

FIGURE 23.2

Update automatically instructs Word to insert a Date field code instead of just the date and time.

image

Updating fields

The word update has been used several times because it's impossible to talk about fields otherwise. Updating a field simply means forcing Word to reevaluate that field in light of any changes that might have occurred either to it directly or to source materials on which it is based.

To update a field, select it and do one of the following:

  • Press F9.
  • Right-click it and choose Update Field.
  • If the field is in a special container that has an Update button, click the field to display the Update button, and then click that button (see Figure 23.3). Containers are discussed further in the next section, “Controlling field display shading.”

Update a field when it has been created or edited manually or when the source or circumstances have changed. Circumstances can include a wide variety of things that affect context. You will learn more about them throughout this chapter.

FIGURE 23.3

Date fields are enclosed in special containers to alert you to their special status. Notice the Update button.

image

Controlling field display shading

When you insert a date field using the Insert Date and Time button, it initially looks like a simple date (depending on your settings—more about that later in this section). However, if you select the date or use the mouse to hover over it, you see something very different, as shown in Figure 23.3. The gray container shown is a special means by which Word displays some fields and a number of other features so that you realize you're not dealing with ordinary text. Not all fields display this way; in fact, most do not. Because date fields have been a frequent source of confusion and problems in the past, however, Microsoft has chosen to display them this way in recent versions of Word.

Most other fields, such as tables of contents and indexes, don't display in containers. How or whether those fields display in a special way is up to you.

To change the way fields are displayed, choose File images Options images Advanced. Scroll down to Show document content, and note the setting for Field shading, shown in Figure 23.4.

In addition to using special containers for some fields, Word can shade fields so that you're aware of their presence in your document. The options are as follows:

  • Never: This is not a good choice for everyday work; see the accompanying Warning.
  • Always: This is a great choice if you're prone to accidentally editing field results by mistake. Use this option if the presence of shading isn't too distracting.
  • When selected: The default; this is a good compromise choice for most users. This means that when a field is contained in your document, you won't necessarily know it until you click on the field and try to edit it.

FIGURE 23.4

To avoid accidentally deleting or mishandling fields, it's a good idea not to set Field shading to Never.

image

The When selected option provides a nice balance of information and aesthetics, as shown in Figure 23.5. With Field shading set to display When selected, Word shades only the field holding the insertion point. If Always had been selected, all four fields would have been shaded.

FIGURE 23.5

The default setting shades only the field you click in.

image

CAUTION

With Field shading set to Never, it's possible to edit the interior of a field's displayed results without realizing it. This frequently happens with dates and tables of contents. The next time you update fields (which can even happen automatically when you print a document), however, your careful edits get zapped! If you have a tendency to do this, consider changing to the Always setting for field shading.

Showing and hiding field codes

The other major option shown in Figure 23.4 is Show field codes instead of their values. Enable this option to display the underlying field code either for diagnostic reasons or so you can manually edit it. If you don't see what you expect to see in an inserted field, toggling a field code display on can help solve the mystery. The same text shown in Figure 23.5 is shown again in Figure 23.6 with field codes displayed. Notice that for the Last Updated line, there is an extra field, LASTSAVEDBY, that should be deleted.

FIGURE 23.6

Displaying field codes enables you to see what's happening behind the scenes and figure out what's causing unexpected results.

image

The Show field codes instead of their values option shown in Figure 23.4 displays all field codes, not just the one in question. To see just the one in question, right-click it and choose Toggle Field Codes, as shown in Figure 23.7. If you select text holding multiple fields before right-clicking, this command will toggle all fields in the selection. Toggling one or several field codes can be helpful when you're trying to understand what's happening with a particular set of related fields. If you are familiar with the syntax of the field, you can also edit the field directly, rather than editing it with the Field dialog box or using other indirect methods (such as Insert images Text images Date and Time or Page Number).

FIGURE 23.7

Right-click a field (or a selection that contains multiple fields) and choose Toggle Field Codes to show the underlying field codes for fields in the selection.

image

NOTE

After creating or editing a field code, don't forget to update it. Otherwise, it will either not display a result at all or not display the new result.

Field keyboard shortcuts

When you need to display all the fields as codes, rather than having to drill into the File images Options images Advanced settings, it's much simpler and quicker to press Alt+F9. Other field-related shortcut keys incorporating F9 or F11, as listed in Table 23.1, perform such actions as updating fields.

TABLE 23.1 Field Keyboard Shortcuts

Shortcut Action
F9 Update fields—updates all fields contained in the current selection.
Ctrl+F9 Insert field characters—inserts new field code braces for manually inserting fields.
Shift+F9 Toggle field display—toggles field code display for fields contained in the current selection.
Alt+F9 View field codes—toggles field code display for all fields in the entire document.
Ctrl+Shift+F9 Unlink fields—converts all qualifying fields in the selection into hard text; once this action is done, the field can't be updated anymore.
Alt+Shift+F9 Do field click—alternative to double-clicking MacroButton and GoToButton fields.
F11 Next field—selects the next field in the document. Field codes do not need to be displayed for this command or the next.
Shift+F11 Previous field—selects the previous field in the document.
Ctrl+F11 Lock fields—prevents fields in the selection from being updated.
Ctrl+Shift+F11 Unlock fields—unlocks fields so that they can be updated.

In Table 23.1, notice the last two commands. Unknown by most users, these aren't used nearly enough, but they are exceedingly useful when you want to control whether a date field, a link to bookmarked text, or some other field can be updated. Select the field (in fact, if it's the very next field in the document you can press F11 to go right to it), and press Ctrl+F11. Press F9 to try to update it. It doesn't work! Press Ctrl+Shift+F11 to unlock it. Now F9 works.

TIP

If you want a good test field for trying out such behavior, insert a Time field, using an option that includes displaying seconds. That way you'll never have to wait more than a second before the field is out of date.

Recall from the beginning of this chapter that some field operations have been replaced by XML relational linking—such as when you insert a link to a picture. In Word 97–2003 compatibility mode, you still get an INCLUDEPICTURE field, but not in a Word 2013 .docx file. What's interesting is that the F9 key works to update the non-field picture links, but Ctrl+F11 does not work to lock them. Worse, once you've updated such a link by pressing F9, Ctrl+Z won't undo the update.

Other shortcut menu tools

In addition to the Toggle Field Codes option shown in Figure 23.7, there are other contextual commands. Note that these appear only when a field is selected:

  • Update Field: See “Updating Fields” earlier in this chapter.
  • Edit Field: This command opens the Field dialog box for the selected field, as shown in Figure 23.8. This enables you to use the interface to make changes in the field, rather than edit the field directly. Use this option if you're uncomfortable with direct field editing and/or you're unfamiliar with the needed syntax. Note that Edit Field does not work with all fields in the same way. For example, it doesn't work with the Table of Contents (TOC) field unless the entire table of contents is perfectly selected. If you get a generic Field dialog box rather than the specific one you're looking for, verify that the selection doesn't include something other than a field code, or return to the original command that created the field (such as Insert images Table of Contents).

FIGURE 23.8

The Field dialog box's Field properties section enables you to pick the options, and it builds the field code behind the scenes.

image

CAUTION

If a block of text is contained in the selection, Word displays the default Field dialog box rather than the setup for any particular field. If you proceed nonetheless, any field you insert will replace all the selected text rather than affecting a single field (unless you have Typing replaces selected text turned off, as described in Chapter 4, “Zapping Word's Top Annoyances”).

Using the Field Dialog Box to Insert a Field

In the Field dialog box, you choose the options you want and Word automatically builds the necessary field code for you. Here's how to use the dialog box to create a field:

  1. Click Insert, click Explore Quick Parts in the Text group, and then click Field to display the dialog box shown in Figure 23.8.
  2. Under Please choose a field, open the Categories drop-down list, and click a field category. If you choose All, all the different possible fields (at least the ones to which the interface provides access) are shown under Field names. The dialog box also provides several categories that can help steer you in a particular direction.
  3. In the Field names list, click the desired field.
  4. Make your selections for any Field properties that appear at the center of the dialog box.
  5. Select applicable choices from any Field options that appear at the right.
  6. Click OK. Word inserts the field code into the document and displays the field results (unless field code display is toggled on).

NOTE

Word has additional field codes that aren't accessible through the Field dialog box. Information on these is beyond the scope of this book, but you can find out more on the Microsoft Developer Network (MSDN) website.

If you're just exploring the Field dialog box, you could click the second item under Field Names and observe the right side of the dialog box. As you choose different fields, the array of Field properties and Field options changes. The offerings on the right are determined by the type of field and its capabilities. For example, some are designed to work with bookmarks, and a list is offered accordingly. Others work with dates, and corresponding date formats are shown from which you can choose.

Caveats for Mergeformat

Note that many fields have an option to Preserve formatting during updates, seen in the lower right in Figure 23.8. When you select this option Word adds a * MERGEFORMAT switch to the field code. For example, a DATE field code with this option might look like this:

{ DATE @ “MMMM d, yyyy” * MERGEFORMAT }

The * MERGEFORMAT switch tells Word to preserve any formatting you might have applied so that in a subsequent update your formatting will be preserved. That is the theory, and it works quite well for some fields, including dates. For example, if you make that date bold, it will stay bold in subsequent updates.

However, it doesn't necessarily work for REF fields to bookmarks for which the contents change, or for a number of other fields. Consider what happens if the bookmarked passage is:

[Now is the time for all good men to come to the aid of their country.]

You can use a REF field to reproduce that text elsewhere in the document. If the bookmark's name is “countrymen,” the field code { REF countrymen * MERGEFORMAT } could reproduce the original text elsewhere in the document. Suppose you add italics to the word good in the reproduced text, but it's not italicized in the original. With the * MERGEFORMAT switch in place, updating the field will leave “good” alone. Without the switch, “good” reverts to its original form.

Now consider what will happen if you completely rewrite the original text so that it no longer contains the word good at all, but still uses the same bookmark. In this case, Word arbitrarily formats the seventh word in italics when you update the REF field! Keep this odd behavior in mind before you rely heavily on the Preserve formatting option. It's best when formatting field results to use only formatting that applies to the entire field result, rather than to individual words.

Field Codes and Hide Codes

Looking back at Figure 23.8, with Categories set to (All) and Field Names set to SaveDate, notice the Field Codes button in the lower-left corner. If you click it, the button face now says Hide Codes. The right part of the dialog box now says Advanced field properties, and includes a Field codes text box with the field information in it, as shown in Figure 23.9.

FIGURE 23.9

With the Field codes box displayed, the Field dialog box provides a place for you to enter the field code, and displays the syntax model below the fill-in box.

image

The syntax model shown below the Field code text box provides information how to manually edit the field. For some fields, the Options button next to Hide Codes is grayed out as unavailable. That doesn't mean that no options are possible for this field code; you can just click Hide codes to redisplay the previous options for the field in the dialog box. When the Options button is active, clicking it opens the Field Options dialog box shown in Figure 23.10.

FIGURE 23.10

Field Options enables you to customize a field without memorizing complicated syntax.

image

Click a listed option on either the General Switches or Field Specific Switches tab, review the Description that appears near the bottom of the dialog box to determine whether you've selected the appropriate option, and then click Add to Field. Repeat as needed, and then click OK to return to the field dialog box. Click OK again if you are finished editing the field.

The next section explains more about field switches, regardless of whether you want to enter them in the Field dialog box or display a field code in the document and edit it manually.

Using Switches to Customize a Field

Some fields are very simple. Their only syntax is the keywords by which they're identified. The field { BIBLIOGRAPHY } for example, uses no parameters whatsoever. Other fields can be rather complex, requiring both parameters and switches to achieve the desired effect. Furthermore, for some reason known only to Microsoft, some fields require quotes around literal arguments, whereas others do not.

Although syntax can vary substantially for various field types, a number of general rules apply. The general form for the field statement is as follows:

{ keyword [instructions] [switches] }

NOTE

Technically, Word distinguishes slightly between what appears in the middle brackets and shorter field-specific switches. But because the Field Options dialog box calls them all switches, this chapter follows suit.

Note that anything inside brackets [] is optional. Anything not in brackets is required.

The keyword can be any the field types (including field types created by third parties for Word add-ins; those fields can be used only if the corresponding add-in has been installed). The field character pair, which you can insert by pressing Ctrl+F9, can also be used to enclose just a bookmark reference, such as {duedate}. In such cases, the REF keyword is implied, and is almost equivalent to {REF duedate}. I say almost equivalent, because the two fields behave differently sometimes. For example, if you apply formatting to a REF field code's displayed results, Word adds a * MERGEFORMAT switch to the field. If you apply formatting to a plain bookmark field that doesn't use REF, Word will not add the switch. If you right-click a REF bookmark field and choose Edit Field, you'll get the full services of the REF field, replete with a list of bookmarks and switches. If you right-click a plain bookmark field, you'll get no services at all.

Anytime the first word in a field statement isn't one of the recognized keywords, Word tries to interpret the field as a bookmark. When manually inserting a field code, if you mistype or if the bookmark name isn't otherwise defined, when you try updating the resulting field Word informs you that something is wrong by yelling “Error! Bookmark not defined.” If you see this error message, it means that you've mistyped a keyword or a bookmark or that a bookmark has been deleted.

The actual ordering of arguments and switches matters sometimes, but not always. As a general rule, switches that affect the entire field precede any arguments. A switch that affects a particular parameter usually appears immediately after the parameter it affects.

You can use three types of general switches. These can be used with a number of different fields and they affect how the results of fields are displayed:

  • Text format
  • Numeric format
  • Date format

Text format switches

Text format switches use the following syntax:

* format

They are used to affect how certain text will appear. The format options can be any of the keywords that follow.

NOTE

Each switch only works with certain fields. For example, adding the * firstcap switch to the AUTHOR field does not change the capping of the username information used by that field.

  • * alphabetic: This switch converts the numerical result of an expression into lowercase letters, producing an alphabetical numbering result. For uppercase letters, capitalize the first letter of the * alphabetic switch: Alphabetic. The numerals 1 through 26 produce a through z, 27 through 52 produce aa through zz, and so on. For example, {= * alphabetic 2} displays as a single lowercase b. If you add 26 to it (28), it displays as two b's, etc. The maximum number you can display this way is 780, which displays as 30 z's. Use this if you're planning a nap.
  • * Arabic: This switch is the default and results in normal Arabic numerals. For example, {=2^16 * Arabic} displays as 65536.
  • * caps: Any text in the resulting expression is displayed in initial caps. For example, with the SET bookmark field {SET greeting “dear senator”}, the corresponding bookmark reference {greeting * caps} would result in Dear Senator.
  • * cardtext: This switch displays a numeric expression in cardinal form. For example, {=666666 * cardtext} displays as six hundred sixty-six thousand six hundred sixty-six. This can be handy if you use Word to write legal documents in which numerical amounts and dates sometimes are spelled out.
  • * CHARFORMAT: and * MERGEFORMAT: The * CHARFORMAT switch affects the character format of text that's displayed. If neither * CHARFORMAT nor * MERGEFORMAT is specified, the text is displayed exactly as it appears in its original form. If * CHARFORMAT is specified, the displayed result has the same character formatting as the first character in the field keyword or bookmark name. This lets you permanently set the formatting of the displayed result. If * MERGEFORMAT is specified, the displayed result takes on the character format of the current result the next time the field is updated. When no format switch is used, note that a reformatted field always reverts to the original format when updated. If you change the text contained in the bookmark when * MERGEFORMAT is specified, any new formatting done to the displayed field result will be applied to the field when it is updated. Without * MERGEFORMAT, the displayed formatting of the field will revert to that of the text it references. Use the following guidelines when you have to decide which switch to use:
    • Use no switch at all when you want to preserve original formatting. You might want to do this for such things as business logos whose original appearance must not vary by context.
    • Use * CHARFORMAT when you want to ensure that the display result matches what you're typing right now, such as boilerplate text, an address, or the signature line in a letter. The first letter of the bookmark will be in your current font and point size (unless you explicitly change it), pretty well guaranteeing that the displayed text will blend in.
    • Use * MERGEFORMAT when you plan to reformat the displayed text and want the formatting retained. You might use this approach for special text—such as a book title or product name—for which the font might vary markedly depending on where you're using it.
  • * dollartext: The dollartext format is a variation of cardtext, producing the kind of result you might want when writing the amount in long form on checks. For example, { = 4577.89 * dollartext} would result in four thousand five hundred seventy-seven and 89/100.
  • * firstcap: The firstcap format capitalizes the first word only in the displayed result. For example, {QUOTE * firstcap “now is the season of our discontent”} would result in Now is the season of our discontent. Note that with the * firstcap switch you would still get the identical result even if the text inside the field were all capitals or alternating capitals and lowercase.
  • * hex: The hex format switch displays a number in hexadecimal form. For example, { = 16384 * hex } displays as 4000. The largest number that can be displayed this way in Word 2013 is 65,535 (FFFF).
  • * lower: The lower format setting displays text in all lowercase. For example, {QUOTE * lower “WHAT DO YOU MEAN ‘STOP YELLING!’”} results in what do you mean ‘stop yelling!’
  • * ordinal: The * ordinal switch adds st, nd, rd, and th endings to numbers. For example, { =5283 * ordinal} produces 5283rd.
  • * ordtext: Ordtext adds ordinal endings to the text versions of numbers. For example, {= 999999 * ordtext} yields nine hundred ninety-nine thousand nine hundred ninety-ninth. That, by the way, is as high as Word will go. The number 1,000,000 results in an error.
  • * ROMAN: The * ROMAN switch dresses your text up in a toga. Just kidding. It yields a Roman numeral. The expression Microsoft Office { =2010 * ROMAN } results in Microsoft Office MMX. Incidentally, the highest you can go is 32,767, which results in MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMDCCLXVII. Higher numbers are met with an error message. The lowest you can go is 1 because, as every math student learns, the Romans had no zero. If you try to display 0, you'll get only a simple space. Try a negative number, and you'll get an error message.
  • * upper: The * upper switch causes the field's text to display in all caps. For example, {QUOTE * upper “tHiS iS mIxEd Up”} rather disingenuously proclaims THIS IS MIXED UP.

Numeric format switches

Numeric format switches, sometimes called numeric picture switches, have the following syntax:

# format

These are quite versatile, enabling you to format numbers in a wide variety of ways.

# (number placeholder)

The # parameter is sometimes a source of confusion. That's because in addition to being used as the overall numeric format switch (#), it can also be used as a specification or argument within the switch—for example, {=6765.44 # $#,.##}. Note that the # in this field is the numeric switch. The additional # parameters specify how the number should appear. In this case, the noted field would produce $6,765.44. The $ means that the result will be preceded by $. The next # is a placeholder for any significant digits to the left of the decimal point. The comma means that commas will be used every three places to the left. The remaining .## reserves two significant digits to the right of the decimal point. The number 6765.444444 would therefore be displayed as $6,765.44.

0 (zero placeholder)

The numeral 0 is used as a placeholder to guarantee the same order of precision in numbers. This is useful when you have multiple formula fields that ordinarily might yield different precisions. For example, it's generally unacceptable to list the same statistic for different individuals using different precisions, such as in the following table:

Courtney 4.216
Ryan 3.7
Colleen 4.4
Matt 4.7231

Suppose these numbers were all exact, and the result of calculations performed by Word. By using the same numeric switch in all the calculation fields (for example, {=59/14 #0.000}), you ensure that all the results are shown to thousandths, with a leading 0 for any that are less than 1 (for example, 0.412 instead of .412).

x

When x is used at the left edge of any other arguments, Word truncates additional digits that don't fit in the reserved space. For example, {=42753 # x#.00} results in 53.00 because x# reserves only two places to the left of the decimal point. When used to the right of the decimal point, x serves the same purpose as #.

. (decimal point)

The decimal point is used in conjunction with # and 0 placeholders to specify the precision of the displayed result.

, (commas for three-digit groups)

The comma is used to insert commas to separate three-digit groups (thousands) to the left of the decimal point. If you want only commas and numbers, the comma and any other number placeholder (except for x) will work. You don't need {=55000 # ###,###} to get 55,000. A simple {=45000 # #,} works just as well.

+ (forcing the plus sign to display)

Include the plus sign to force the positive or negative display of the number. No sign is displayed for 0. Consider the following example:

The temperature in Frostbite Falls, Minnesota, was {=sum(weathertable[A1]) # +#}.

If the A1 cell in a table bookmarked as weathertable says −57, it will display as −57. If it's 37 in the table, then the field result will display +37, and the residents will be putting on their shorts and T-shirts.

; (semicolon)

The semicolon is used to specify different formats for positive, negative, and 0. If a single semicolon is used, the picture format to the left controls the display of positive and zero values, and the picture format to the right of the semicolon controls the display of negative numbers. If two semicolons are used, the first argument specifies positive format, the second specifies negative format, and the third specifies zero format.

For example, consider the switch # *+###*;^+###^;=0.#=. The numbers 65, −7, and 0 would display respectively as *+65*, ^−7^, and =0.0=. Why would you do that? Because you can!

' (single quote)

Single quotes are used to insert literal text into the number display when the text contains characters otherwise reserved for use as part of the format switch. When you do this, the entire numeric format must be enclosed in double quotes.

Enclosing reserved characters in single quotes prevents the single-quoted text from being interpreted as a numeric switch argument. For example,

{ =8.9 # “Please add #.0% sales tax”}

displays as

Please add 8.9% sales ta

Recall that x is a switch argument. For this to work properly, the x in tax must be enclosed in single quotes:

{ =8.9 # “Please add #.0% sales ta‘x’” }

You can, of course, enclose the entire literal text in single quotes. Minimum quoting is used here to demonstrate why it's necessary. Alternatively, move to a state that doesn't have a sales tax.

Date format (date-time picture switches)

Date-time picture switches have the following syntax:

@ format

They enable you to format dates in a variety of ways, as detailed in Table 23.2.

TIP

You can specify a desired default format using the Date and Time dialog box. Choose Insert images Text images Date and Time. Highlight the format you want to use for the default and click Default. Choose Yes to confirm. Back in the Date and Time dialog box, click OK to insert a date, or Cancel if you're simply changing the default. The default was changed when you confirmed changing the default; canceling doesn't cancel the change.

TABLE 23.2 Time and Date Picture Switch Format Elements

Characters Effect
AM/PM or am/pm AM and PM or am and pm, respectively
A/P or a/p A and P or a and p, respectively
D Date, with no leading zero
Dd Date, with leading zero
Ddd Abbreviated name of the day of the week (SUN, MON, etc.)
Dddd Full name of the day of the week (Sunday, Monday, you know the rest)
H Hour, 12-hour format with no leading zero
Hh Hour, 12-hour format with leading zero
H Hour, 24-hour format with no leading zero
HH Hour, 24-hour format with leading zero
M Numeric month, no leading zero
MM Numeric month, leading zero
MMM First three letters of month (Jan, Feb, etc.)
MMMM Full name of month (March, April, etc.)
M Minutes, no leading zero
Mm Minutes, leading zero
S Seconds, no leading zero
Ss Seconds, leading zero
y or yy Year, two-digit format (07, 08, etc.)
Yyyy Year, four-digit format (2013, 2014)

Date formats use key letters to represent parts of dates and times, as shown in Table 23.2. These key letters affect only the component that is displayed, not the capitalization. You must add the appropriate * switch to achieve different forms of capitalization. The field {date @ “MMM”} produces Aug (an uppercase M produces months, while a lowercase m produces minutes). You would need to add * upper to get AUG. See the following section for other exciting ideas.

Switch combinations

Some of the switches can be combined. For example, * CHARFORMAT or * MERGEFORMAT can be combined with any other format. The field {quote * CHARFORMAT * ordtext “9”} produces ninth (in italics because the q in quote is in italics). However, none of the numeric arguments can be combined with case arguments, except for alphabetic.

Categories

The Field dialog box separates the fields into several categories. In this section we will look at each category, the fields they contain, and what those fields are used for.

Date and Time

Word provides six different date and time fields. Of the six, note that only the Date field itself, which provides the current date, uses the special document control container.

  • CreateDate: The date the document was created
  • Date: The current date
  • EditTime: Cumulative time that the document has been open
  • PrintDate: The last date that the document was printed
  • SaveDate: The last date the document was saved
  • Time: The current time

All of these except for EditTime can be used as either Time or Date fields depending on the picture switches applied. Note also that for each of the Time and Date fields, when you display the dialog box, as shown in Figure 23.11, the top format is shown (such as 11/21/2012), even if the selected field name is Time.

If you select the field and then just click OK, accepting the default date format, that may not be the format displayed by the field. In the case of Date, you will get the default date format (which you can change as shown earlier). In the case of Time, you will get just the time. For CreateDate, PrintDate, and SaveDate, however, you will get a combination of the default date and the time. Therefore, if you want one of those three—and you generally want the time as well—you don't need to build a formatting switch. It's already been done for you, the dialog box's display notwithstanding.

FIGURE 23.11

The Field dialog box enables you to set up any of the date and time fields (except for EditTime) using any combination of date and time elements.

image

Document Automation

The document automation fields are used mostly in building automated forms. The fields can be used to perform logical operations and to allow the user to run a macro, send special instructions to the printer, or go to a bookmark. Six fields are provided:

  • Compare: Used in mail merge operations to test the values of data fields.
  • DocVariable: Used to display the contents of a document variable that was created by a macro.
  • GoToButton: Used to transfer the insertion point to a bookmark location. This field has been superseded by the Hyperlink field.
  • If: Often used in mail merge documents to control the flow and to create conditional statements that control whether specific mail merge fields are printed.
  • MacroButton: Used to run a macro.
  • Print: Used to send special codes to your printer.

Document Information

Document information fields are taken from the Document Properties stored behind the scenes for a file. You can view some of them with the File images Info choice, and they display at the right side of the screen that appears. Click Show All properties below the list of Properties to see the full list of available properties.

The Document Information category contains a variety of document properties that you can insert into the document. With the exception of the DOCPROPERTIES field, each of the field codes can be inserted directly into the document to display the corresponding datum about the document. Note that some fields such as COMMENTS, SUBJECT, and TITLE generally must be entered by someone (using the document panel or Properties dialog box). A number of these are automatically created by Word, such as FILESIZE, NUMCHARS, NUMPAGES, and NUMWORDS. The 14 document information fields are as follows:

  • AUTHOR: The name of the person who created the document. This comes from the File images Options images General settings.
  • COMMENTS: Has nothing to do with Word's Comments feature, and instead is any comments entered.
  • DOCPROPERTY: Used to insert any of 26 document properties into the current document, not just the list included in the document information fields.
  • FILENAME: The name of the current file, optionally including the path.
  • FILESIZE: The stored size of the file, available in several different formats.
  • INFO: Used to insert any of 17 summary information items.
  • KEYWORDS: Any document keywords that happen to have been inscribed in Document Properties.
  • LASTSAVEDBY: The name of the user who last saved changes to the document.
  • NUMCHARS: The number of characters in the document, excluding white space.
  • NUMPAGES: The total number of physical pages in the document
  • NUMWORDS: The number of words in the document.
  • SUBJECT: The subject document information field, if populated.
  • TEMPLATE: The name of the currently attached document template.
  • TITLE: The title of the document, if one has been assigned. This is not the same as the filename.

Equations and Formulas

This group is used to perform calculations, manipulate characters, construct equations, and display symbols. Though the formula (=) field will still attract a few diehard users in Word 2013, for the most part the functionality offered by this group is for backward compatibility. Four fields are provided:

  • = (Formula): Used to perform calculations and format numbers.
  • Advance: Used to position characters for special effects and for simulating characters not available through the user's installed fonts.
  • Eq.: Used to create equation-like effects. This is provided for backward compatibility. Use Insert images Symbols images Equation instead.
  • Symbol: Used to insert symbols. Use this approach instead of Insert images Symbols images Symbol if you need to retain information about the exact nature of the symbol being inserted.

Index and Tables

The index and tables fields are used to build and maintain tables of contents, indexes, and tables of authorities. The seven fields in this category are as follows:

  • Index: Creates an index based on XE fields
  • RD: Creates an index, table of contents, table of figures, or table of authorities using marked entries or heading styles in multiple documents
  • TA: Used to mark a table of authorities entry
  • TC: Used to manually mark a table of contents entry
  • TOA: Creates a table of authorities based on TA fields
  • TOC: Creates a table of contents using outline levels (heading styles) or TC entries
  • XE: Used to mark index entries

Links and References

These fields are used to link content into Word documents from external files as well as from other parts of the current Word document. Fields are provided in those cases both for backward compatibility and to allow for different methods if other options are preferred. The 11 fields in this category are as follows:

  • AutoText: Inserts the contents of a Building Blocks gallery item into the current document. You might use this rather than insert an entry using the Building Blocks gallery or Quick Parts gallery if the contents/value of the underlying entry changes. For example, the item might contain an address, a telephone number, or boilerplate text that is subject to being updated. If you include a reference to the AutoText instead of the AutoText itself, the document can be more dynamic and updateable.
  • AutoTextList: Creates a shortcut menu based on AutoText entries in a template that's currently available. The entry list can be based on the styles applied to the AutoText entries. For example, if you have a style named Color Choices, any entry formatted with that style will appear in the list. When the user right-clicks the AutoTextList item, the list of Color Choices appears. If you click one of the items, the AutoTextList field is replaced by the AutoText item chosen.
  • Hyperlink: Inserts a hyperlink to a URL, file, or other location available on a disk, a network location, the Internet, or an intranet.
  • INCLUDEPICTURE: Used to link to a supported graphics file. Word 2013 defaults to an XML link instead of using INCLUDEPICTURE, although the field is still supported. An advantage of the INCLUDEPICTURE field is that it can be locked with Ctrl+F11 to prevent accidental updates and unlinking. When working in compatibility mode, Word defaults to INCLUDEPICTURE links because the XML method is not supported in earlier versions of Word.
  • INCLUDETEXT: Similar to INCLUDEPICTURE, but used to link to a nongraphic file. Word 2013 still uses the INCLUDETEXT field when you insert a link to a file, however.
  • LINK: This field links information you copy and paste from another application to the original source file using OLE (object linking and embedding). You typically would use Paste images Paste Special, choose the desired object type, and enable the Paste link option.
  • NOTEREF: Used to insert a footnote or endnote reference mark that's been bookmarked so you can make multiple references to the same note, or to cross-reference footnotes or endnotes.
  • PAGEREF: Inserts the page number of a bookmarked location; used for cross-references.
  • QUOTE: Used to insert literal text. This field often is used with the IF field to conditionally insert different text based on a comparison with data from a database of some kind.
  • REF: Used to insert bookmarked text. For example, you might bookmark the table number in a table caption and use that reference in the text. If other tables are inserted or deleted and the numbering changes, the REF field that refers to the bookmarked table number can be updated.
  • STYLEREF: Used to insert the text of the nearest occurrence (searching up or down) of a style relative to the location of the STYLEREF field, or some datum related to that style occurrence. Often used in making dictionary-type headings wherein the first and last words defined on the page appear at the top of each page.

Mail Merge

The fields included in the Mail Merge group are used in constructing mail merge documents of the type shown when you choose Start Mail Merge in the Mailing dialog box. See Chapter 22, “Data Documents and Mail Merge,” for the full scoop.

Some of the fields in the Mail Merge category are also shown under Document Automation. The 14 Mail Merge fields are as follows:

  • ADDRESSBLOCK: This field inserts a mail merge address block. Using the ADDRESSBLOCK field is an alternative to specifying the address elements individually. You generally insert this field by clicking Address Block in the Mailings Ribbon tab. See Chapter 22 for additional information.
  • ASK: This field prompts you to provide information. It assigns a bookmark to the answer you provide, and the information is stored internally. A reference to the bookmark can then be used in the mail merge document to reproduce the information you type. A default response to the prompt can also be included in the field. The ASK field displays only as an empty bookmark in the mail merge document, so don't be surprised if you don't see a result.
  • COMPARE: See the field of the same name under “Document Automation.”
  • DATABASE: This field inserts data into your document in the form of a Word table. When you create the field, you are prompted for a database from which records can be filtered and selected. The result can appear either as a normal Word table or as a field masquerading as a table. One use for this field is to extract data into a file that can then be used for mail merges. You might want to do this when the larger dataset is tied to a server and will be inaccessible to the ultimate mail merge users. You might also do this simply to present data in a table in a Word document. If you keep the database result in the form of a field, it can be updated when and if the underlying data change.
  • FILL-IN: This field prompts you to enter text and then uses your response in place of the field in the mail merge document. This is similar to the ASK field, except that the information can be used only in one place.
  • GreetingLine: This field inserts a greeting line into your mail merge document. It usually is inserted by means of the Greeting Line button in the Mailings tab. See Chapter 22 for additional information.
  • IF: See the field of the same name under “Document Automation.”
  • MERGEFIELD: This is used as a token placeholder for a mail merge field inserted from a database. For example, rather than Dear John, you might see Dear <<FirstName>> in your document. Or you might instead see <<GreetingLine>>. See Chapter 22 for additional information.
  • MERGEREC: When you're doing a mail merge, the MERGEREC field serves as a counter of records in the data file and doesn't count the number of documents actually printed. This field is incremented by the presence of NEXT and NEXTIF fields. If you skip records using SKIPIF, MERGEREC is incremented nonetheless.
  • MERGESEQ: This field provides a counter of mail merge documents that actually result from a merge. If you merge the entire database and do not change the base sorting, and if no records are skipped, MERGESEQ and MERGEREC will be identical.
  • NEXT: The NEXT field is used to include more than one record in a given document. Ordinarily, when you're doing a mail merge, one document is printed for each record. With the NEXT field, however, you can include multiple records in a single document. This can be useful when you need to refer to several addresses from a data file.
  • NEXTIF: The NEXTIF statement works like the NEXT field except that it advances to the next record only if an expression being evaluated is true.
  • SET: The SET field is used to change the text referred to by a bookmark. For example, an occurrence of the text July 4, 2014, might be bookmarked as dayoff in one part of the document, and dayoff might be referred to in other parts of the document with a REF field. If you want to change the date referred to by the bookmark, you can either change the original underlying text at the site of the original bookmarked instance of July 4, 2014, or you can use a SET field to change it.
  • SKIPIF: The SKIPIF field is used to cancel processing of the current database record during a mail merge. For example, you might use it to screen out a particular ZIP code.

Numbering

Numbering fields are used to insert certain kinds of numbering into your documents. The 10 field codes in the Numbering category are as follows:

  • AUTONUM: The AUTONUM field inserts an automatic paragraph number field. The resulting numbers are displayed as 1., 2., 3., and so forth. AUTONUM is incremented in each paragraph. If you include multiple AUTONUM fields within the same paragraph, they will all display the same number. General formatting switches are ignored by this field, and updating is automatic—you don't need to press F9. The AUTONUM field is designed for numbering paragraphs or sections of a document. Some users find it less flaky than Word's Numbering tool and automatic list numbering, especially in legacy documents from Word 2003 and earlier.
  • AUTONUMLGL: AUTONUMLGL inserts an automatic paragraph number field code whose results are displayed in legal style as 1., 1.1., 1.1.1., etc. AUTONUMLGL is tied to Heading level styles (Heading 1 is 1., Heading 2 is 1.1., and so on). All general format switches are ignored by this field and updating is automatic each time a paragraph is inserted or deleted. AUTONUMLGL displays the same as AUTONUM when used in non-Heading-style paragraphs.
  • AUTONUMOUT: AUTONUMOUT inserts an automatic paragraph number field code whose results are displayed with traditional outline numbering (I., A., 1., a., and so on). Like AUTONUMLGL, AUTONUMOUT works with Heading level styles, and updating is fully automatic.
  • BARCODE: This field inserts a BARCODE into the current document. If you see a Bookmark not defined error code instead of a bar code, toggle field codes and remove the  switch. According to Word this feature has been removed. It has and it hasn't. Other parts of the Word interface no longer provide access to it, but it remains as a field code for two reasons: a) for compatibility with legacy documents and b) to annoy the post office. Use it at your own risk.
  • LISTNUM: This field inserts a set of numbers anywhere in a paragraph. Unlike the AUTONUM fields, LISTNUM is incremented each time you use it. Also unlike the AUTONUM fields, LISTNUM supports several switches that enable you to control how numbering is performed, the starting number, and the list level: 1), a), i), (1), (a), (i), and so on (feel free to experiment to see what each level produces). A common instance in which you'd use LISTNUM is when you're numbering things within a paragraph and don't want to worry about having to renumber them when you insert or remove items. For example, “I needed to 1) make a list of things to do, 2) do the things on the list, and 3) add additional things to the list.” In this case, a LISTNUM field would be used to create 1), 2), and 3). Like AUTONUM, LISTNUM is updated instantly and automatically anytime another LISTNUM field is inserted or deleted. If you make a to-do list, however, LISTNUM won't do the things on the list for you.
  • PAGE: Use this field to insert the current page number. It's used most often in creating page numbers in headers and footers.
  • REVNUM: The REVNUM field comes from the Advanced Properties Statistics tab. The revision number is incremented each and every time the document is saved. For the average paranoid but savvy Word user, this makes REVNUM essentially worthless. For example, REVNUM indicates that this particular chapter has now been saved 212 times. Note that REVNUM is unrelated to the Versions feature from Word 2003 (which Word 2013 does not support).
  • SECTION: The SECTION field inserts the section number of the current section. This can be useful in setting up some kinds of compound numbering that numbers pages by section, but in which numbering is not being applied to a Heading style that varies by section.
  • SECTIONPAGES: The SECTIONPAGES field inserts the number of pages in the current section. When you're numbering by section and want to include the length of each section, a common page numbering setup would be Page {section}–{page} of {sectionpages}.
  • SEQ: The SEQ field is used to insert a sequence number into a document. SEQ is used to number chapters, tables, figures, illustrations, lists, or anything else not already covered by a built-in numbering system. Though it's more complex than Word's built-in numbering system for numbered lists, many users found that in past versions of Word, the SEQ field was a lot more predictable and dependable than the numbered lists feature, and that its use resulted in fewer problems. You can create any number of independent numbering sequences in a document, and switches provide full control over numbering features.

User Information

User information corresponds to the User Name and Initials fields in File images Options images General, as well as to the Mailing Address field found in File images Options images Advanced images General. The three user information fields are as follows:

  • USERADDRESS: Your mailing address, if you chose to enter it
  • USERINITALS: Your initials, if you entered your name in the Personalize settings
  • USERNAME: Your name, if you entered it in the Personalize settings

Summary

In this chapter you've learned about field codes: what they are, how to insert them, and why you might want to. You've learned about numerous fields available in Word and how to use them. You should now be able to do the following:

  • Insert a date field
  • Use various methods to toggle field code display, Ctrl+Shift+F9 to convert a field result into actual text, and other shortcut keys for working with fields
  • Insert a field using the Field dialog box, including specifying options and switches for the field
  • Edit a field manually or in the Field dialog box
  • Decide when to use the * CHARFORMAT or * MERGEFORMAT formatting switches
  • Lock a date field to keep it from being unintentionally updated
  • Use field codes to set up a variety of different kinds of page numbering
  • Understand the difference between a FILLIN and an ASK field, and when to use each
  • Use the LISTNUM field to a) set up this kind of numbering within a paragraph and b) avoid having to renumber this kind of within-paragraph numbering when you add or remove an item
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset