View Single Post
  #2   Report Post  
Posted to microsoft.public.word.mailmerge.fields
macropod macropod is offline
external usenet poster
 
Posts: 1,002
Default Rounding using Numeric Switch

Hi Pixie,

Word can't handle numbers longer than 15 digits as anything other than a string. What you're trying to do with the numeric picture
switch amounts to a mathematical function.

You can get around this, as explained below, but it's probably better to modify your data source so that it can output a field with
only the digits you need, then format your mergefield as:
{MERGEFIELD myfield \# 0000}

If you can't modify the data source, here's a workaround:

1. Select your original mergefield and press Ctrl-F9 to embedd it in another field, thus:
{ {MERGEFIELD myfield} }
2. Type the following between the field braces:
{SET Data {MERGEFIELD myfield}}
3. Create a new pair of fields by pressing Ctrl-F9 twice and type the following between the field braces:
{=MOD({=INT({REF Data}/100)-1},100)+1}
This formula extracts the first two of the last four digits from the string.
4. The next part looks complicated, but it's really quite straightforward. What you need to do is to create two multi-layered sets
of embedded fields, thus:
{IF{REF Data }= "*1?" 1 {IF{REF Data }= "*2?" 2 {IF{REF Data }= "*3?" 3 {IF{REF Data }= "*4?" 4 {IF{REF Data }= "*5?" 5 {IF{REF
Data }= "*6?" 6 {IF{REF Data }= "*7?" 7 {IF{REF Data }= "*8?" 8 {IF{REF Data }= "*9?" 9 0}}}}}}}}}

{IF{REF Data }= "*1" 1 {IF{REF Data }= "*2" 2 {IF{REF Data }= "*3" 3 {IF{REF Data }= "*4" 4 {IF{REF Data }= "*5" 5 {IF{REF Data }=
"*6" 6 {IF{REF Data }= "*7" 7 {IF{REF Data }= "*8" 8 {IF{REF Data }= "*9" 9 0}}}}}}}}}

Each set of 9 nested IF fields is a compilation 9 sets of {IF{REF Data}= "*#?" # !}, where the:
€¢ field braces (i.e. '{ }') are created in pairs via Ctrl-F9;
€¢ '*' is a wildcard representing all numbers in the field preceding the number you're looking for;
€¢ '#' is the number you're looking for;
€¢ '?' is a wildcard representing each succeeding number in the field; and
€¢ '!' represents the next number or nested IF test.

5. Once you've got these created, select all the fields, including the mergefield, and press Ctrl-F9 one last time, then type
'QUOTE' between the left-most pair of field braces. This wraps all your fields inside a QUOTE field. An advantage of using the QUOTE
field wrapper is that you can have paragraph marks separating the nested IF fields, to keep the layout just that bit more
comprehensible, without any effect on the output.

6. Finally press F9 to update the fields. You're now ready to run your mailmerge.

Cheers
--
macropod
[MVP - Microsoft Word]
-------------------------

"Pixie" wrote in message ...
Hello!
I'm trying to display the last 4 digits of a 16 digit account number in a
mail merge letter. I'm using the numeric switch {MERGEFIELD myfield\ # x###}

If I just use my field alone, it displays the entire 16 digit account number
fine with no rounding but if I use the switch, it displays the last 4 digits
but it rounds them. From what I read, it would only round to the right of a
decimal. I have no decimals in my number. What gives?!!!

Thanks for your help. Love the forum!