1. It's difficult to make suggestions about how to proceed without know a
bit more about how Word is getting its data and what programming options you
have. e.g.
a. which version of Word can you rely on?
b. can you use VBA macros?
c. can you modify the data source as Word sees it? (what type of data
source does Word think it is dealing with

Signature
Peter Jamieson
http://tips.pjmsn.me.uk
> eld differently...
>
[quoted text clipped - 19 lines]
>
> I am using Word 2003 SP2.
Thanks Peter,
a) I am using Word 2003 SP2. 11.8106.8107.
b) I can use VBA Macros, although the documents generated are in RTF format
so the macros will have to be written in normal.doc, and i would then have to
update normal.doc on all machines. Another method would be preferable.
c) The data is being drawn from a .net application. I would prefer not to
edit the source data as it already applies to several thousand records.
There is no easy way to alter the source data, or the format of the source
data.
d) I appreciate they are not strictly merge fields but, essentially, they do
the same thing for me - i'm not really sure of the ins and outs of this i'm
afraid.
Basically if field 200123 contains the number 1234123412341234 and my word
document contains [!matter:200123], then the word document will populate
1234123412341234 when generated.
The [!matter...] codes work the same way if placed inside { } braces, i do
use them in conjunction with switches and field codes elsewhere for other
tasks.
I think that the only way to acheive what i need is to change the data AFTER
it has been merged to the document. The field codes mod() etc did not work
for me, they returned a *Syntax error....
Although i would prefer to avoid VBA for reasons above, is there a way of
using VBA to select strings of a merged field (i.e. select char 1,2,3,4)
which i could then allocate a bookmark to?
Once again, thanks for your time.
Andy.
> 1. It's difficult to make suggestions about how to proceed without know a
> bit more about how Word is getting its data and what programming options you
[quoted text clipped - 44 lines]
> >
> > I am using Word 2003 SP2.
Peter Jamieson - 22 Oct 2007 17:48 GMT
> d) I appreciate they are not strictly merge fields but, essentially, they
> do
> the same thing for me - i'm not really sure of the ins and outs of this
> i'm
> afraid.
It sounds as if you are using a third party application that has its own
approach to merging data. But the question then is: does it actually modify
the RTF before the RTF is even opened in Word? Or what?
> The field codes mod() etc did not work
> for me, they returned a *Syntax error....
Did you use ctrl-F9 to insert each pair of {} braces? Unfortuantely, if
there is a third party program preprocessing Word content in some way it's a
bit difficult to tell what it's going to do and when!
> I think that the only way to acheive what i need is to change the data
> AFTER
> it has been merged to the document.
You then face the difficulty of having to have code in a template (which you
mentioned) or having some other way to insert the correct result (cf.
http://tips.pjmsn.me.uk/t0004.htm , but to do that you have to have a .dsn
or .udl file on every target system.
The only other approach IMO: process the .rtf yourself using code, stuffing
in the values you want from the database, before the .rtf even reaches Word.
I guess you would only have to do that for the fields that your existing
approach cannot cope with.

Signature
Peter Jamieson
http://tips.pjmsn.me.uk
> Thanks Peter,
> a) I am using Word 2003 SP2. 11.8106.8107.
[quoted text clipped - 96 lines]
>> >
>> > I am using Word 2003 SP2.
macropod - 23 Oct 2007 12:08 GMT
Hi Andy,
You can suppress the digits in the middle of the string, but the field coding to do so is a bit complicated. That's because Word
can't do maths with more than 15 digits, so a workaround is needed. Here's the code:
{QUOTE{SET Data {MERGEFIELD Value}}{=INT(Data/10000000000000000)}"-****-****-"
{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}}}}}}}}}
{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}}}}}}}}}}
The above field coding includes 4 sets of nested IF fields. Each set of nested IF fields is a compilation 9 sets of {IF{REF Data}=
"*#?" # !}, where the:
• field braces (i.e. '{ }') are created in paird 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.
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.
Cheers

Signature
macropod
[MVP - Microsoft Word]
-------------------------
> Thanks Peter,
> a) I am using Word 2003 SP2. 11.8106.8107.
[quoted text clipped - 77 lines]
>> >
>> > I am using Word 2003 SP2.