View Single Post
  #6   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Doug Robbins - Word MVP on news.microsoft.com Doug Robbins - Word MVP on news.microsoft.com is offline
external usenet poster
 
Posts: 407
Default How to format Zip Code from 9 to 5

The {SET ID {MERGEFIELD ZipCode} sets the zip code as the text of a bookmark
with the name of ID
-{ ID } evaluates to -99999-9999 whereas -ID is treated mathematically and
evaluates to -99999+9999
so =-{ID}-ID evaluates to -99999-9999-99999+9999 or -99999-99999
so what is actually happening is that the digits in the zip code after the -
are being stripped off and what is left is a negative number that is twice
the first five digits of the zip code
Then the {=-{=-{ID}-ID}/2} changes the sign and divides the number by 2 so
that it is just the first five digits of the zip code.
The {SET EXP1{=-{=-{ID}-ID}/2}} assigns that to the bookmark EXP1, which is
then displayed by the {QUOTE EXP1 }

Regards,
Doug Robbins - Word MVP, originally posted via msnews.microsoft.com

"macropod" wrote in message
...
Hi Doug,

Your mission, if you choose to accept it, is to figure out how the code
works ...

--
Cheers
macropod
[MVP - Microsoft Word]


"Doug Robbins - Word MVP on news.microsoft.com"
wrote in message ...
I should have known that you would come up with a way of doing it.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com

"macropod" wrote in message
...
Hi Leslie,

You can eliminate the unwanted portions via a field coded as:
{QUOTE{SET ID {MERGEFIELD ZipCode}}{SET EXP1{=-{=-{ID}-ID}/2}}{EXP1}}
Where 'ZipCode' is the name of the data field containing your Zip Codes.

With this coding, any of 75043-0000 or 75043--000 or 75043-000 will be
returned as 75043.

Note: The field brace pairs (ie '{ }') for the above example are created
via Ctrl-F9 - you can't simply type them or copy & paste them from this
message.

--
Cheers
macropod
[MVP - Microsoft Word]


"Leslie" wrote in message
...
I hope this makes sense! We have a glitch in our computer software
that
automatically places zeros in the place of the zip code plus 4 numbers
when
there are no numbers there, 75043-0000 or 75043--000 or 75043-000.
Since we
do not have control over programming we need to overcome this problem,
hopefully, by using MS Word. We are okay with not seeing the plus four
numbers if they are there, because most often we only get the standard
5
numbers.

I have tried different formatting using Bookmarks, and this works if
there
are only zeros in the plus 4 field, but if there ARE numbers what I get
is
Word subtracting the plus four and creating a whole new zip code.

{IF {ZIP} 99999 "{ ZIP \# "00000'-'0000"}""{ZIP \# "00000"}"}
takes this number 75841-1111 and makes it 74730.

Is there any way to get Word to just truncate the last four numbers and
only
show the first five?