Article ID: 120279
Article Last Modified on 8/16/2005
APPLIES TO
- Microsoft Word 6.0 Standard Edition
- Microsoft Word 6.0a
- Microsoft Word 6.0c
- Microsoft Word 6.0 Standard Edition
- Microsoft Word 95 Standard Edition
- Microsoft Word 95a
- Microsoft Word 6.0 for Macintosh
- Microsoft Word 6.01 for Macintosh
- Microsoft Word 6.01 for Macintosh
- Microsoft Word 98 for Macintosh
This article was previously published under Q120279
SUMMARY
When your data source contains a mixture of five- and nine-digit postal
codes, you can use an IF field to evaluate and format the merged postal
codes.
MORE INFORMATION
Use one of the following methods to merge a data source containing a
mixture of five- and nine-digit postal codes:
NOTE: To create the field code braces, use the keyboard combination CTRL+F9
(Windows) or Command+F9 (Macintosh). Be sure that each record of your data
source contains a postal code; otherwise, an error message appears for that
record.
Method 1: Determine Greater Than/Less Than 99999 Method
NOTE: Use this method only if your data source doesn't contain hyphens.
{IF {MERGEFIELD PostalCode} > 99999 {MERGEFIELD PostalCode
\# "#####'-'####"} {MERGEFIELD PostalCode}}
If the postal code data is larger than 99999, it is a number with more
than five digits. Therefore, it will be merged with the formatting switch
(\#). If it is equal to or less than 99999, it is a five-digit postal
code and will not include the formatting switch (\#) when merged.
Method 2: Calculation Method
NOTE: Use this method only if your data source contains hyphens.
{IF {=ABS({MERGEFIELD PostalCode \# "####'-'#####"})} <>
{MERGEFIELD PostalCode} {MERGEFIELD PostalCode \# "#####'-'####"}
{MERGEFIELD PostalCode}}
The formatting of the first merge field has four number signs followed by
five number signs. This appears incorrect but is necessary for the
calculation that takes place.
This field code may not work if the postal code field is from a Microsoft
Access data source and if that field is formatted as a number. If the
postal code starts with a 0, for example "01234", Word interprets it as
"1234". To work around this behavior, format the postal code field as text
(rather than numbers) in Microsoft Access. Then postal codes beginning with
zero will be available in Word.
Word does not include fields that count the number of characters in another
field. So, to determine the number of digits in the postal code field, the
field construction in this method takes advantage of two facts: (1) when
you format a numeric field to include a hyphen, the hyphen is treated by
other fields as a subtraction sign; (2) numbers that begin with a zero are
evaluated the same as numbers that don't begin with a zero. For example,
"01234" is evaluated by Word as equal to "1234".
The PostalCode field is placed in the main document with a hyphen, so that
the formula can operate on it. Its absolute value is taken, which converts
the number to a positive value. This new number is compared to the literal
postal code. If the numbers differ, it's a nine-digit code and this is
printed, with the format switch to keep any leading zeros. If the
calculated number is different from the literal postal code, the postal
code is printed as is (without the format switch).
Additional query words: us u.s. post office zip zipcode 4Plus 4 Plus four printmerge mailmerge print mail 8.0 8.00
Keywords: kbhowto kbmerge kbfield KB120279