A Closer Look at Field Formatting

In this section, you'll learn some advanced techniques for controlling how field results appear. Suppose that you've made an important point somewhere in a large report. It's so important that you've boldfaced it for emphasis. Now you want to use a field to insert that phrase into your executive summary. But in that context, where everything's important, you don't want it to be boldfaced.

Well, you could insert the field result and reformat it manually?but it would then revert to the bold formatting anytime you updated your fields. Or you could lock that field?but if you ever want to update the substance of the field, then what? Obviously, neither of these solutions is ideal. Fortunately, Word provides field formatting switches that can do the job.

If you use a field that consists of only the field name, such as { NUMCHARS }, controlling the formatting of your field results is easy. Format the first character of the field name to look as you want your text to look. If you want bold italic text, your field should look like this:


{ NUMCHARS }

If the field also contains instructions, again format the first character of the field name the way you want it. Then, add the following switch to the end of your field code:


\* charformat

For instance,


{ INCLUDETEXT "report.doc"  \* charformat }

One more alternative is to manually format your field result and instruct Word not to change the formatting no matter what. This occurs when you check the Preserve Formatting During Updates check box in the Field dialog box?a check box that is checked by default. (If you enter a field manually, you must add the \* MERGEFORMAT switch.)

There's only one catch to using Preserve Formatting During Updates or \* MERGEFORMAT. When you do, Word counts words and takes their formatting literally. If you've formatted the fourth and fifth words in your field result as bold italic, then those words will always be bold italic?even if the field result changes and the fourth and fifth words happen to change. Let's say the field you insert consists of the following:

According to Yankelovich, cohort marketing techniques can help you craft messages that address the emotional needs of the generation you need to reach.

Later, you edit the source copy a bit. You could wind up with something like this:

Yankelovich cohort marketing techniques can help you craft messages that address the emotional needs of the generation you need to reach.

This literalism means you should use \* MERGEFORMAT only when changing field results aren't likely to introduce a problem.

Formatting Field Numbers

You can use \* CHARFORMAT and \* MERGEFORMAT to format numbers as well. But numbers present some unique issues. What if a number should read one way in one location and a different way where a field inserts it? Or what if you need your field to return a number in an unusual format, with an unusual alignment, or in an unusual sequence?

In fields that typically return numbers, Word offers a wide variety of built-in number format options through the Field dialog box. And you can customize these options even further if you need to.

Figure 23.7 shows the Field dialog box for the { SECTION } field, which inserts a document's current Section number. Two types of number formatting options are available here:

  • The options in the Format scroll box represent sequences of numbering you can use; Word inserts these with the \* switch.

  • The options in the Numeric Format scroll box represent formats you can use; Word inserts these with the \# switch.

Figure 23.7. The { SECTION } field offers different kinds of number formatting in the Format and Numeric Format scrollboxes.

graphics/23fig07.jpg

The following sections take a closer look at each type of switch.

Using Word's Built-In Number Sequences

Word provides several built-in sequencing options for the numbers that appear in field results. For example, you can format them as Roman numerals, convert them to words, or display them in a currency format such as you might see on a check or purchase order. Table 23.4 lists the primary choices Word offers.

Table 23.4. Number Sequences Provided by Word

Sequence

Switch

What It Does

Example

1, 2, 3,…

\* Arabic

Default format uses Arabic numbers

27

a, b, c,…

\* alphabetic

Converts number into corresponding lowercase letters, "doubling up" letters after the 26th letter

aa

A, B, C,…

\* ALPHABETIC

Converts number into corresponding uppercase letters, "doubling up" letters after the 26th letter

AA

i, ii, iii,…

\* roman

Converts number into lowercase Roman numerals

xxvii

I, II, III,…

\* ROMAN

Converts number into uppercase Roman numerals

XXVII

1st, 2nd, 3rd,…

\* Ordinal

Converts number to follow ordinal sequence

27th

First, Second, Third,…

\* Ordtext

Converts number to text that follows ordinal sequence

twenty-seventh

One, Two, Three,…

\* Cardtext

Converts number to text that follows cardinal sequence

twenty-seven

hex,…

\* Hex

Converts number to hexadecimal

1B

Dollar Text

\* DollarText

Converts number to "check" format

Twenty-seven and 00/100

For example, if you want your field to report the section number as "three" rather than "3," you can select the A, B, C,… sequence from the Format scroll box. If you insert the field and then view it, you would see the following:


{ SECTION \* alphabetic }

Or you could use a { REVNUM } field to insert a sentence such as


NOTE: This is the fifth revision

where the word "fifth" was generated by the following field:


{ REVNUM \* OrdText }
Using Word's Built-In Numeric Formats

What if you're perfectly happy with plain old Arabic numbers (1, 2, 3,…), but you need to control how many digits appear or where decimal points or commas are used, or you want to display a dollar sign before your field result? The options in the Numeric Format scroll box enable you to control these and other elements.

When you choose one of these numeric formats, Word inserts a \# switch and places the numeric format in quotation marks. For example, the following field inserts the file size, in megabytes (the \m switch specifies megabytes). The \# switch at the end of the field tells Word to use commas as separators between thousands (for example: 3,215 rather than 3215):


FILESIZE \m \# "#,##0" 
Customizing Numeric Formats to Your Specific Needs

Word's built-in numeric formats are likely to be sufficient to handle most of your fields, but occasionally you may have to create your own:

  • You may need to create a numeric format for an expression. Oddly, Word does not enable you to use the Field Options dialog box to do so; you must do so manually.

  • You may need a format Word does not provide, such as a field result with three decimal places, or a field result that formats numbers with a foreign currency symbol such as # or ¥.

TIP

To insert a symbol into a dialog box such as the Field dialog box, insert it into your document using the Insert, Symbol dialog box; cut it into the Clipboard; open the dialog box where you want to paste it; and press Ctrl+V to paste it.


For situations in which you cannot use a built-in format, you must create the format manually. Word calls this painting a numeric picture.

Here's a simple example. Suppose that you're using fields to set up a list of numbers. If you use Word's default format, they look like this:

.8

15.96

29

18.2

That's sloppy?and if you choose to right-align your numbers you're no better off:

.8

15.96

29

18.2

You would prefer that each field result use the same number of decimal places so that they line up nicely when right-aligned:

.8

15.96

29

18.2

TIP

In some cases, you can achieve the same result using a decimal tab.


To create a numeric picture Word can use to create field results with three decimal places, you can use two of Word's built-in placeholders: # and 0. Within a numeric picture, the # symbol tells Word, "If there's no number in that location, insert a blank space." The 0 symbol tells Word, "If there's no number in this location, insert a 0."

Therefore, to get the cleaned-up list, use the following switch with each field:


\# "###." 

NOTE

Quotation marks are optional unless you're combining the number with text.


NOTE

A numeric picture using # or 0 placeholders rounds off a fractional number that requires more digits than you allowed. For example, the field code { =1/3 \# "##" .} by default displays the result 0.33.


Table 23.5 describes several placeholders and other characters you can use in numeric formats.

Table 23.5. Characters You Can Use in Numeric Pictures

Character

What It Does

Sample Usage

Sample Field Result

[No switch]

Enters the value in the default format

{= 1/4}

0.25

#

Substitutes a blank space where no number is present; rounds off extra fractional digits

{=1/3 \# "$#.##" }

$ .33

0

Substitutes a zero where no number is present

{=1/4 \# "00." }

00.

$

Places a dollar sign in your field result

{=1/4 \# "$#.00" }

$0.25

+

Places a plus or minus sign in front of any field result not equal to zero

{=1/4 \# "+#.##" }

+.25

?

Places a minus sign in front of negative numbers (leaves positive numbers alone)

{= 1/4 \# "?#.##" }

?.25

.

Inserts a decimal point

{=1/4 \# "#.#" }

0.3

,

Inserts a comma separator (note: also use at least one 0 or #)

{=/2 \# "#,0" }

4,

;

Enables you to specify more than one option for "$###.00; displaying numbers, depending on whether the numbers are positive, negative, or zero (options should be specified in the order shown:positive, then negative, then zero)

{revenue- expenses \# ($###.00); 0" }

$.00 or ($.00) or 0 depending on actual field result

x

If placed on the left, truncates digits to its left; if placed on the right, truncates digits to its right

{ \# "#x##" }

75

"text"

Includes text or symbols in numeric picture; places the entire numeric picture in regular quotation marks and the text in single quotation marks

{= "#### 'lira'" }

lira

Formatting Dates and Times in Field Results

As with numbers, you can format dates and times in many ways. Usually, the quickest way to format date and time is to create your field with Insert, Field; the Field dialog box has most of the formats you need. However, as with numbers, you may occasionally need a specialty format.

The date-time switch is \@. Similar to what you've already seen with numbers, \@ creates a date-time picture?a model of how your dates and times should look. This date-time picture is usable with the following fields: { CREATEDATE }, { DATE }, { PRINTDATE }, { SAVEDATE }, and { TIME }.

You can use the characters in Table 23.6 and Table 23.7 in date-time pictures. You can also add separators, such as colon (:), dash (-), or slash (/).

CAUTION

In date/time formatting, a character's meaning can change depending on its capitalization and the number of times you repeat the character. For instance, if you capitalize M in a date-time field, Word interprets that as month; lowercase m is recognized as minute.


Table 23.6. Characters You Can Use in Date Formatting

Character

What It Does

Sample Usage

Sample Field Result

No switches (Default { DATE }field)

Inserts default date format

{ DATE }

7/6/99

M

Month in numeric format, 1?12

{ DATE \@ "M" }

7

MM

Month in numeric format, adding a zero to months that have only one digit; for instance, 01?12

{ DATE \@ "MM" }

07

MMM

Month as three-letter abbreviation

{ DATE \@ "MMM" }

Jul

MMMM

Month, spelled out

{ DATE \@ "MMMM" }

July

d

Day of month in numeric format, 1?31

{ DATE \@ "d" }

6

dd

Day of month in numeric format, 01?31

{ DATE \@ "dd" }

06

ddd

Day of week, as three-letter abbreviation

{ DATE \@ "ddd" }

Thu

dddd

Day of week, spelled out

{ DATE \@ "dddd" }

Thursday

y

Year (last two digits)

{ DATE \@ "y" }

99

yy

Year (all four digits)

{ DATE \@ "yy" }

 

Table 23.7. Characters You Can Use in Time Formatting

Character

What It Does

Sample Usage

Sample Field Result

No switches (Default{ TIME } field)

Inserts default time format

{ TIME }

12:15 PM

h

Hour, based on a 12-hour clock running from 1 to 12

{ TIME \@ "h" }

8

hh

Hour, based on a 12-hour clock running from 01 to 12

{ TIME \@ "hh" }

08

H

Hour, based on a 24-hour clock running from 0 to 23

{ TIME \@ "H" }

17

HH

Hour, based on a 24-hour clock running from 00 to 23

{ TIME \@ "HH" }

06

m

Minute, running from 0 to 59 (must use lowercase m)

{ TIME \@ "m" }

3

mm

Minute, running from 00 to 59 (must use lowercase m)

{ TIME \@ "mm" }

03

AM/PM

Morning/afternoon data in the format AM or PM

{ TIME \@ "h:mm AM/PM" }

9:30AM

am/pm

Morning/afternoon data in the format am or pm

{ TIME \@ "h:mm am/pm" }

9:30am

A/M

Morning/afternoon data in the format A or P

{ TIME \@ "h:mm A/P" }

9:30A

a/p

Morning/afternoon data in the format a or p

{ TIME \@ "h:mm a/p" }

9:30a

Now for a couple of examples. Suppose that you want to automate the creation of a list of daily specials for your restaurant. You want a field that automatically inserts the correct day of the week in the following sentence:


Welcome! Here are our specials for today, Saturday:

You can build a { DATE } field that displays only the day of the week (not the month or date):


{ DATE \@ "dddd"  }

Or perhaps you need to abbreviate the current month and day, but you don't need to include the year at all:


Mar 27

Use the following field:


{ DATE \@ "MMMM d"  }


    Part I: Word Basics: Get Productive Fast
    Part II: Building Slicker Documents Faster
    Part III: The Visual Word: Making Documents Look Great
    Part IV: Industrial-Strength Document Production Techniques
    Part VI: The Corporate Word