View Single Post
  #14   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Peter Jamieson Peter Jamieson is offline
external usenet poster
 
Posts: 4,582
Default Word mailmerge how to do multiple If statements

The limit for nesting is around 19 or 20 levels. It has been documented (I
think the documentation says "20", but it depends how you count), but
a. I cannot point you to a definitive statement
b. it's possible it has changed in Word 2007.

Peter Jamieson
"Pearl" wrote in message
...
Hi Peter and Ed. I tried out the suggestion for nested If statements from
Ed
using a simple data source in Excel 2003 to a Word 2003 merge doc and it
worked really well. I got to 9 nested Ifs and put in a dummy code to test
the
FalseText with no problems.
The reason I originally raised the query was because I was having problems
getting data out of a 3rd party software system into a merge doc. Only one
of
the code conversions worked and I thought that this was because of the way
I
was constructing the If statements. Turns out that the system is only
recording one code when it should be recording more - so I think a fix is
required!!
Thanks for the great advice here. My query seems to have generated further
queries relating to different versions of Word. Well I use Office 2000 at
work so I'll be trying out my test mail merge that I've created in 2003
there
on Monday so I'll let you know if it still works :-)

Still don't know how many nested IFs Word will take, I need about 16 in
all
so I'll keep going and let you all know how I get on?


Still don't know how many nested Ifs Word will take, I need about 16 in
all
so I'll keep going and let you all know how I get on.
"Peter Jamieson" wrote:

I've now had another look at this on Word 2000 SP3 (not fully patched
though) and the current patched version of Word 2003.

Using relatively simple tests (i.e. may not be the whole story):
a. the behaviour is the same in both versions
b. the print and the preview are the same on both versions, but the
results
when merging to a new document are different
c. for fields inside an INCLUDETEXT, the technique described in my
previous
post consistently achieves suppression on both versions of Word, i.e.
unless
someone knows a better way, it's the way to go.

{ IF "{ MERGEFIELD myfield1 }" = ""
"" "{ MERGEFIELD myfield1 }
" }{ IF "{ MERGEFIELD myfield2 }" = ""
"" "{ MERGEFIELD myfield2 }
" }

d. MERGEFIELDs inside an IF /in the main document/ (e.g.

{ IF 1 = 1 "{ MERGEFIELD a }
{ MERGEFIELD b }" "" }

are never suppressed

e. When you merge to a new document, there is a difference between the
behaviour of an INCLUDETEXT that is nested in an IF in the main document,
and an INCLUDETEXT that is not nested:

The result of an { INCLUDETEXT "pathname" } is that
1. the INCLUDETEXT is retained
2. fields are not suppressed
3. the output document looks the same as the preview and printed version

The result of an { IF 1 = 1 "{ INCLUDETEXT "pathname" }" "" } is that
4. the INCLUDETEXT is resolved
5. fields are suppressed, as long as they are not also nested inside an
IF
inside the INCLUETEXTed document
6. the output document may therefore not look like the preview and
printed
version.

Peter Jamieson

"Peter Jamieson" wrote in message
...
FYI blank line suppression does not work with fields nested in other
fields (such as INCLUDETEXT, IF) in Word 2002/2003. Or at least some
versions of it. Although I think it did work with Word 2000,
a. I probably mostly merged to new documents, not the printer
b. various aspects of field behaviour have been changed with service
packs
and security updates in Word 2000. This /could/ be one of them. If so,
it
could be that the only way you will get these fields to function
correctly
is to use the other, more complex technique of inserting blank lines
when
the fields are not empty, e.g.

{ IF "{ MERGEFIELD myfield1 }" = ""
"" "{ MERGEFIELD myfield1 }
" }{ IF "{ MERGEFIELD myfield2 }" = ""
"" "{ MERGEFIELD myfield2 }
" }

I'm not sure I can get at my Word 2000 system right now but when I can
I'll take a look. Which Word SR/SP are you using?

Peter Jamieson

"Peter" wrote in message
...
Thanks again Ed.

Really appreciate all your advice!

I am using Ver 2000.

I have tried various things you have mentioned, but no luck. The code
I
have
I initially set with information from Microsoft, combined with your
initial
suggestions. I have a link to a screen shot I took of the code I am
using. I
did try keying in the code as you showed Pearl but the documents would
not
come up. The code in the link gives me the documents, just will not
supress
blank lines unless I merge to a new document.

http://img.photobucket.com/albums/v2...g?t=1177710767

Thanks again . . .

Peter