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 Microsoft Word mail-merge operation to format the postal codes.
This article describes a way to ensure consistent output, regardless of whether the data source (address list) contains hyphens in the postal code field.
For example, if your data source contains five-digit postal codes, the resulting postal code is displayed as follows:
However, if your data source contains a nine-digit postal code, with or without a hyphen, the resulting postal code appears as follows:
back to the top
How to create a merge field for postal codes
In Word, use the following field:
{ IF { =ABS ( { MERGEFIELD PostalCode \# "####'-'#####" } ) } <> { MERGEFIELD PostalCode }¶
{ MERGEFIELD PostalCode \# "#####'-'####" } { MERGEFIELD PostalCode } }
NOTES:
back to the top
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 postal code field, the field construction provided 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 start with a zero are evaluated in the same way as numbers that do not start with a zero. For example, "01234" is evaluated by Word as equal to "1234".
The postal code field is placed in the main document with a hyphen, so that the formula can operate on it. The formula takes the field's absolute value, which converts the number to a positive value, and then compares this new number to the literal postal code. If the numbers differ, this means that the code is nine-digits, and it is printed with formatting to retain any leading zeros. If the calculated number is different from the literal postal code, the postal code is printed as is.
back to the top