WD: Formatting a Combination of 5 and 9 Digit ZIP Codes

Last reviewed: February 3, 1998
Article ID: Q120279
The information in this article applies to:
  • Microsoft Word for Windows, versions 6.0, 6.0a, 6.0c
  • Microsoft Word for Windows NT, version 6.0
  • Microsoft Word for Windows 95, versions 7.0, 7.0a
  • Microsoft Word for the Macintosh, versions 6.0, 6.0.1 6.0.1a
  • Microsoft Word 97 for Windows
  • Microsoft Word 98 Macintosh Edition

SUMMARY

When your data document contains a mixture of five-digit and nine-digit ZIP Codes, you can use a field in Word to format ZIP Codes if they do not contain hyphens. This field is useful when your data comes from another data source and doesn't contain hyphens in the nine-digit ZIP Codes. This field will operate whether the data document does or does not contain hyphens.

MORE INFORMATION

Use the following field:

   {IF {=ABS({MERGEFIELD zip \# "####'-'#####"}) }<> {MERGEFIELD zip}
   {MERGEFIELD zip \# "#####'-'####"} {MERGEFIELD zip}}

NOTES:

To create the special field code braces use the key combination CTRL+F9 (Windows) or Command key+F9 (Macintosh). Using the "{" and "}" keys on the keyboard will not work.

Be sure that each record contains a ZIP Code; otherwise, you'll get an error message for that record.

You can change the merge field name from "ZIP" to something else, but nothing else in the formula can be changed.

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.

Note that single quotation marks surround the hyphens.

If you have created your data document using the Mail Merge Helper in Word, the default field name for the ZIP code is "Postal_Code." Substitute "Postal_Code" for "zip" when creating the merge field.

NOTE: This code may not work if the ZIP Code field is from a Microsoft Access data source and if that field is formatted as a number. If the zip code starts with a 0, for example "01234," Word will interpret it as "1234." To work around this behavior, format the ZIP Code fields as text (rather than as numbers) in Microsoft Access. Then, ZIP Codes beginning with zero will be available in Word.

How the Field Works

Word does not include fields that count the number of characters in another field. So, to determine the number of digits in the ZIP field, the field construction above 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 ZIP 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 ZIP Code. If the numbers differ, it's a nine-digit code and this is printed, with formatting to keep any leading zeros. If the calculated number is different from the literal ZIP Code, the ZIP Code is printed as is.


Additional query words: postal codes us u.s. post office Zipcode Postal
Code 4Plus 4 Plus four format switch merge printmerge mailmerge print mail
8.0 8.00
Keywords : kbfield kbmerge macword ntword winword word6 word7 word95 word97 kbualink97
Version : WINDOWS:6.0,6.0a,6.0c,7.0,7.0a,97; MACINTOSH:6.0,6.0.1,6.0.1a,98
Platform : MACINTOSH WINDOWS
Issue type : kbhowto


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: February 3, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.