Microsoft KB Archive/284705

= WD2000: How to Format a Combination of Five-Digit and Nine-Digit Postal Codes =

Article ID: 284705

Article Last Modified on 2/11/2001

-

APPLIES TO


 * Microsoft Word 2000 Standard Edition

-



This article was previously published under Q284705





For a Microsoft Word 2002 version of this article, see 284718.



SUMMARY
When your data source (address list) contains a mixture of five-digit and nine-digit postal codes, you can use a field in your Word mail merge to format the result to contain a hyphen in a nine-digit postal code.

The field contained in the &quot;More Information&quot; section of this article provides a consistent output, regardless of whether the data source (address list) contains or does not contain hyphens in the PostalCode field.

For example, if your data source contains five-digit postal codes, the resulting postal code appears as:

98052

If your data source contains a nine-digit postal code with or without a hyphen (dash), the resulting postal code appears as:

98052-6399



MORE INFORMATION
Use the following field:

{ IF { =ABS ( { MERGEFIELD PostalCode \# &quot;####'-'#####&quot; } ) } <> { MERGEFIELD PostalCode }¶

{ MERGEFIELD PostalCode \# &quot;#####'-'####&quot; } { MERGEFIELD PostalCode } }¶

NOTES:  You cannot copy and paste this field code from this article into your Word mail-merge main document. If you do, the text is not resolved as a field, and your Word mail-merge main document will not contain a MERGEFIELD. To create the special field code braces ({ }), use the key combination CTRL+F9. Using the &quot;{&quot; and &quot;}&quot; keys on the keyboard does not work. To create the paragraph mark (¶), press ENTER. To view the paragraph marks in your Word document, click Show/Hide on the standard toolbar. Be sure that the name of the postal code field is PostalCode. Be sure that each record contains a postal code; otherwise, an error message similar to the following appears for that record

A field calculation error occurred in record n.

where n is the record of your data source that does not contain a value in the PostalCode field. 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.</li> Note that single quotation marks surround the hyphens.</li> This code may not work if the PostalCode 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 &quot;01234&quot;, Word interprets it as &quot;1234&quot;. To work around this behavior, format the PostalCode fields as text (rather than as numbers) in Microsoft Access. Then postal codes beginning with zero will be available in Word.</li></ul>

How the Field Works
Word does not include fields that count the number of characters in another field. Therefore, to determine the number of digits in the PostalCode field, the field construction shown earlier in this article takes advantage of two facts:
 * When you format a numeric field to include a hyphen, the hyphen is treated by other fields as a subtraction sign.
 * Numbers that begin with a zero are evaluated the same as numbers that do not begin with a zero. For example, &quot;01234&quot; is evaluated by Word as equal to &quot;1234&quot;.

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 is a nine-digit code, and this is printed with formatting to keep any leading zeros. If the calculated number is different from the literal postal code, the postal code is printed as is.

Additional query words: us u.s. post office zipcode zip code 4plus 4 plus four format switch merge printmerge mailmerge print mail

Keywords: kbinfo kbmerge kbfield KB284705

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.