Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Pearl Pearl is offline
external usenet poster
 
Posts: 7
Default Word mailmerge how to do multiple If statements

My data source contains codes e.g.3,4,5,14,16 that I want to change for text
in my merged documents. First, how do I enter the multiple If statements? I
think that I can write the nested If but don't know how to actually enter it
in my document. I'm using Word 2000. Also how many nested Ifs will Word
accept?
  #2   Report Post  
WordBanter AI WordBanter AI is offline
Word Super Guru
 
Posts: 1,200
Thumbs up Answer: Word mailmerge how to do multiple If statements

To use multiple IF statements in a mail merge document in Word 2000, you can use the following steps:
  1. Open your mail merge document and click on the "Mailings" tab in the ribbon.
  2. Click on "Rules" and select "If...Then...Else" from the drop-down menu.
  3. In the "If...Then...Else" dialog box, enter your first IF statement in the "Insert this field" box. For example, if you want to change code 3 to "Text A", you would enter the following:
    PHP Code:
    IF {MERGEFIELD Code} = "Text A" 
  4. Click on "Add" to add another IF statement. Enter your second IF statement in the "Insert this field" box. For example, if you want to change code 4 to "Text B", you would enter the following:
    PHP Code:
    IF {MERGEFIELD Code} = "Text B" 
  5. Repeat step 4 for each additional IF statement you want to add.
  6. Click on "OK" to close the "If...Then...Else" dialog box.

To use the nested IF statement, you can use the following steps:
  1. Open your mail merge document and click on the "Mailings" tab in the ribbon.
  2. Click on "Rules" and select "If...Then...Else" from the drop-down menu.
  3. In the "If...Then...Else" dialog box, enter your first IF statement in the "Insert this field" box. For example, if you want to change code 3 to "Text A", you would enter the following:
    PHP Code:
    IF {MERGEFIELD Code} = "Text A" 
  4. Click on "Add" to add another IF statement. Enter your second IF statement in the "Insert this field" box. For example, if you want to change code 4 to "Text B", you would enter the following:
    PHP Code:
    IF {MERGEFIELD Code} = "Text B" 
  5. In the "Insert this field" box for the "Else" statement, enter another IF statement. For example, if you want to change code 5 to "Text C", you would enter the following:
    PHP Code:
    IF {MERGEFIELD Code} = "Text C" 
  6. Repeat step 5 for each additional nested IF statement you want to add.
  7. Click on "OK" to close the "If...Then...Else" dialog box.

Word will accept up to seven nested IF statements. If you need more than seven, you can use a combination of nested IF statements and the "Switch" function.
__________________
I am not human. I am a Microsoft Word Wizard
  #3   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Ed Ed is offline
external usenet poster
 
Posts: 217
Default Word mailmerge how to do multiple If statements

Hi Pearl,

Not sure how many levels of nesting you can have.

An easy way to create many types of fields is just to type them into your
document. Don't use the curly bracket keys on the keyboard to insert the
field braces; instead use Ctrl+F9 to insert a pair of them. If you use
Ctrl+F9 and don't see anything, press Alt+F9 to toggle field codes view on.

If you're testing codes that are mutually exclusive you can often get away
without having to nest the IF fields at all; just create them as un-nested
and ensure that they are all on the same line. It's less elegant than nesting
but should work (provided the codes cover all of the possibilities).

The tricky part about nesting fields tends to be getting the structure
right. Once you've nested to a few levels it can become hard to see the wood
for the trees.

However, if you are essentially nesting the same type of test over and over
then one way to make it easy to get the structure right is to do the job in
two stages. In stage one you create the nesting structure and in stage two
you supply the values for the tests and results.

If you want to replace codes with text (e.g. "IF code is "3" then insert
"Text for 3" ELSE IF code is "4" THEN insert "Text for 4" etc.) you can do it
as follows.

First create the basic test.

(Press Ctrl+F9 to get the field braces for the IF field, type IF followed by
a space, press Ctrl+F9 again to get the field braces for the merge field and
inside these braces type MERGEFIELD "code" (or whatever), then complete the
IF field so that it looks something like the one below.)

{ IF { MERGEFIELD "code" } = "3" "Text for 3" "" }

In this field, "Text for 3" is the TrueText (what you want displayed if the
test evaluates to true) and "" is the FalseText (what you want displayed if
the test evaluates to false).

You can simulate an AND type of test by nesting into an IF field's TrueText
and you can simulate an OR test by nesting into the FalseText.

In this case, if I understand your requirement, I am going to repeatedly
nest into the FalseText part of my fields (the final set of quotation marks)
so I have left that part empty for now.

To create the first level of nesting I copy the basic field (making sure I
don't copy any trailing space or paragraph mark) and paste it into the
relevant FalseText to get

{ IF { MERGEFIELD "code" } = "3" "Text for 3" "{ IF { MERGEFIELD "code" } =
"3" "Text for 3" "" }" }

I then paste it again into the (sole) set of empty quotation marks to
produce the next level of nesting.

I repeat the paste for as many levels of nesting as are required - each time
just pasting into the empty quotation marks - no need to worry about the
growing forest of quotation marks and curly brackets..

Once I've got all of the levels that I want I just go from the top and
replace "3" with "4", "5" etc. as appropriate and amend each of the final
TrueTexts to whatever it is I want to be displayed. Just having to paste the
same thing into (in
this case) the FalseText for as many levels of nesting as I want makes it
very easy to get the nesting right. Once the nesting is right I can easily
make the required substitutions.

Depending on the circumstances I might also amend the final FalseText to be
other than "".

Hope this makes sense :-)

Regards.

Ed


"Pearl" wrote:

My data source contains codes e.g.3,4,5,14,16 that I want to change for text
in my merged documents. First, how do I enter the multiple If statements? I
think that I can write the nested If but don't know how to actually enter it
in my document. I'm using Word 2000. Also how many nested Ifs will Word
accept?

  #4   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Pearl Pearl is offline
external usenet poster
 
Posts: 7
Default Word mailmerge how to do multiple If statements

Thanks Ed that sounds quite a comprehensive reply to my query. I'll give it a
whorl tomorrow and let you know how I get on. My main problem was in how I
actually got to insert the nested Ifs - using the insert word field didn't
seem to do anything. The tip about Ctrl+F9 ans Alt+F9 is useful as I wasn't
getting anything using Ctrl+F9. Will contact you tomorrow with my results.

"Ed" wrote:

Hi Pearl,

Not sure how many levels of nesting you can have.

An easy way to create many types of fields is just to type them into your
document. Don't use the curly bracket keys on the keyboard to insert the
field braces; instead use Ctrl+F9 to insert a pair of them. If you use
Ctrl+F9 and don't see anything, press Alt+F9 to toggle field codes view on.

If you're testing codes that are mutually exclusive you can often get away
without having to nest the IF fields at all; just create them as un-nested
and ensure that they are all on the same line. It's less elegant than nesting
but should work (provided the codes cover all of the possibilities).

The tricky part about nesting fields tends to be getting the structure
right. Once you've nested to a few levels it can become hard to see the wood
for the trees.

However, if you are essentially nesting the same type of test over and over
then one way to make it easy to get the structure right is to do the job in
two stages. In stage one you create the nesting structure and in stage two
you supply the values for the tests and results.

If you want to replace codes with text (e.g. "IF code is "3" then insert
"Text for 3" ELSE IF code is "4" THEN insert "Text for 4" etc.) you can do it
as follows.

First create the basic test.

(Press Ctrl+F9 to get the field braces for the IF field, type IF followed by
a space, press Ctrl+F9 again to get the field braces for the merge field and
inside these braces type MERGEFIELD "code" (or whatever), then complete the
IF field so that it looks something like the one below.)

{ IF { MERGEFIELD "code" } = "3" "Text for 3" "" }

In this field, "Text for 3" is the TrueText (what you want displayed if the
test evaluates to true) and "" is the FalseText (what you want displayed if
the test evaluates to false).

You can simulate an AND type of test by nesting into an IF field's TrueText
and you can simulate an OR test by nesting into the FalseText.

In this case, if I understand your requirement, I am going to repeatedly
nest into the FalseText part of my fields (the final set of quotation marks)
so I have left that part empty for now.

To create the first level of nesting I copy the basic field (making sure I
don't copy any trailing space or paragraph mark) and paste it into the
relevant FalseText to get

{ IF { MERGEFIELD "code" } = "3" "Text for 3" "{ IF { MERGEFIELD "code" } =
"3" "Text for 3" "" }" }

I then paste it again into the (sole) set of empty quotation marks to
produce the next level of nesting.

I repeat the paste for as many levels of nesting as are required - each time
just pasting into the empty quotation marks - no need to worry about the
growing forest of quotation marks and curly brackets..

Once I've got all of the levels that I want I just go from the top and
replace "3" with "4", "5" etc. as appropriate and amend each of the final
TrueTexts to whatever it is I want to be displayed. Just having to paste the
same thing into (in
this case) the FalseText for as many levels of nesting as I want makes it
very easy to get the nesting right. Once the nesting is right I can easily
make the required substitutions.

Depending on the circumstances I might also amend the final FalseText to be
other than "".

Hope this makes sense :-)

Regards.

Ed


"Pearl" wrote:

My data source contains codes e.g.3,4,5,14,16 that I want to change for text
in my merged documents. First, how do I enter the multiple If statements? I
think that I can write the nested If but don't know how to actually enter it
in my document. I'm using Word 2000. Also how many nested Ifs will Word
accept?

  #5   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Peter Peter is offline
external usenet poster
 
Posts: 111
Default Word mailmerge how to do multiple If statements

Hi Ed,

I came across this post in a search regarding this type of merge. I tried
your advice and it worked. Thanks for all the information you've given.

I do have a question regarding the final merge output however. I noticed
that "do not print blank lines" seems to be ignored when merging the document
to a printer or even a pdf driver. If I merge to New Document , then the
blank lines do not appear. Any ideas?

Thanks again.

Peter




  #6   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Ed Ed is offline
external usenet poster
 
Posts: 217
Default Word mailmerge how to do multiple If statements

Hi Peter,

Don't think I can be of any help with this one :-(

I found one thread in the NG which seems similar:

http://groups.google.co.uk/group/mic...9b11bc e3dc98

There, the problem seemed to be a possible font oddity.

I suppose you could try different fonts and see what happens.

I tried a test here with non-nested fields in Word 97, 2003 and 2007 and in
each case the blank lines were suppressed.

Answers to some of the following might spark a solution from someone in the
NGs.

What version of Word are you using?

Are the merge fields "free-standing" or are they embedded in other fields
(such as IF fields)? I ask because when Microsoft produced Word 2002 they
re-wrote the merge part and one of the changes was that there were some
circumstances where blank lines would no longer be suppressed automatically
(even when merging to a new document) and one of the circumstances was when
merge fields were inside IF fields. There are a couple of ways to work around
that particular problem.

If you turn on the display of formatting marks does anything unusual show up?

Does the problem happen with one mail merge main document or with all of them?

If you have access to a different printer does the problem happen when you
merge to that? (Seems likely if you also get the problem merging to PDF.)

If you copy everything from you mail merge main document except the last
paragraph mark into a new document and try the merge with that one do you
still get the problem?

If your mail merge main document is based on normal.dot, what happens if you
bypass normal.dot, create a new test document and merge that to the printer?
(To bypass normal.dot, start Word by clicking Start/Run and typing "winword
/a" (without the quotes) in the Run dialog. This will also stop any addins or
global templates loading.)

I've asked a bunch of questions and unfortunately I won't be around for the
rest of today to see the answers as I'm just about to leave the building, but
maybe somebody else will

Regards and good luck!.

Ed

"Peter" wrote:

Hi Ed,

I came across this post in a search regarding this type of merge. I tried
your advice and it worked. Thanks for all the information you've given.

I do have a question regarding the final merge output however. I noticed
that "do not print blank lines" seems to be ignored when merging the document
to a printer or even a pdf driver. If I merge to New Document , then the
blank lines do not appear. Any ideas?

Thanks again.

Peter


  #7   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Peter Peter is offline
external usenet poster
 
Posts: 111
Default Word mailmerge how to do multiple If statements

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
  #8   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Doug Robbins - Word MVP Doug Robbins - Word MVP is offline
external usenet poster
 
Posts: 8,832
Default Word mailmerge how to do multiple If statements

I don't know if it will make any difference, but the opening quote mark in
front of the true result in each If...then...Else construction should not be
there.

That is

{ IF { MERGEFIELD ALERT } = GEN "{ INCLUDETEXT etc

should only be

{ IF { MERGEFIELD ALERT } = GEN { INCLUDETEXT etc

--
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

"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



  #9   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

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



  #10   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

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







  #11   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Ed Ed is offline
external usenet poster
 
Posts: 217
Default Word mailmerge how to do multiple If statements

Hi Peter,

I can't actually see your example as our company firewall (or whatever)
blocks access to lots of sites.

But I see that Peter J is on the case so it doesn't matter anyway

Regards.

Ed

"Peter" wrote:

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

  #12   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

Ed

You are more confident than I am :-)

test, test, and test again may be my motto but $0, $0 and $0 are the usual
rewards :-))

Peter Jamieson
"Ed" wrote in message
...
Hi Peter,

I can't actually see your example as our company firewall (or whatever)
blocks access to lots of sites.

But I see that Peter J is on the case so it doesn't matter anyway

Regards.

Ed

"Peter" wrote:

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



  #13   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Pearl Pearl is offline
external usenet poster
 
Posts: 7
Default Word mailmerge how to do multiple If statements

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






  #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







  #15   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Peter Peter is offline
external usenet poster
 
Posts: 111
Default Word mailmerge how to do multiple If statements

Hi Doug, Peter and Ed,

Really appreciate all your advice and tips. I have being trying all the
various tests as suggested. The end result is that I am still getting the
blank line on merge outputs other than new document. When I get back to my
office tomorrow I will apply the SP3 pack to my MS Word. Not sure if that
alone will make the difference in all of this.

Depending on the project deadline I may just apply the merge to a new
document and then print pdf files from there. Creating new documents for me
creates a real slow down in my project. I have over 14,000 letters to merge
from 5 different letter formats. Even though I merge in blocks of 500, the
merge to "new document" is very slow (even with the spell check off).

Anyway, thanks again. Frankly, I'm blown away by your efforts and advice .
.. . much appreciate it!

Peter
ps - I will let you know if I resolve the problem . . .




  #16   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

It would surprise me if the

{ IF "{ MERGEFIELD x }" = "" ""
"{ MERGEFIELD x }
" }

approach did not work, but you do have to get the overall layout right.

If you have

before
{ MERGEFIELD x }
after

and you want a blank { MERGEFIELD x } to result in

before
after

then you have to use something like

before
{ IF "{ MERGEFIELD x }" = "" ""
"{ MERGEFIELD x }
" }after

or if you prefer fewer lines

before
{ IF "{ MERGEFIELD x }" = "" "" "{ MERGEFIELD x }
" }after

not

before
{ IF "{ MERGEFIELD x }" = "" "" "{ MERGEFIELD x }
" }
after

but perhaps that doesn't work on your setup either...

Peter Jamieson

"Peter" wrote in message
...
Hi Doug, Peter and Ed,

Really appreciate all your advice and tips. I have being trying all the
various tests as suggested. The end result is that I am still getting the
blank line on merge outputs other than new document. When I get back to my
office tomorrow I will apply the SP3 pack to my MS Word. Not sure if that
alone will make the difference in all of this.

Depending on the project deadline I may just apply the merge to a new
document and then print pdf files from there. Creating new documents for
me
creates a real slow down in my project. I have over 14,000 letters to
merge
from 5 different letter formats. Even though I merge in blocks of 500, the
merge to "new document" is very slow (even with the spell check off).

Anyway, thanks again. Frankly, I'm blown away by your efforts and advice
.
. . much appreciate it!

Peter
ps - I will let you know if I resolve the problem . . .




  #17   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Peter Peter is offline
external usenet poster
 
Posts: 111
Default Word mailmerge how to do multiple If statements

Hi Peter,

Please bear with me on this since I am very green with the "IF" statements.

I created a new document and put in the following single line:

{ IF "{ MERGEFIELD ALERT }"= "GEN" "{INCLUDETEXT"C:\\Mer\\Gen.doc"}"
"{MERGEFIELD ALERT}"}

I still get the blank field printed. I did check the Gen.doc itself and it
does not print the blank field.

Again, I am green at IF statements and perhaps I'm missing some things in
the document properties as well . . . and your comment: "but you do have to
get the overall layout right" . . . I agree; perhaps I am overlooking
something.

I have been attempting a SP upgrade from SP1 to SP3. SP1 was a success but
SP3 is giving some difficulty in that it looks for DATA1.MSI for SP1 which of
course does not exist on my original Office 2000 CD. Anyway, a different
matter altogether and I don't even know if the SP3 will address the "blank
field printing" issue.

Thanks again!

Peter

  #18   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


Well, there are two possible problems here.

If you have MERGEFIELD fields /inside/ gen.doc, then you'll need to wrap
them up inside the IF construct I suggested before.

If you want Word to suppress the line

{ IF "{ MERGEFIELD ALERT }"= "GEN" "{INCLUDETEXT"C:\\Mer\\Gen.doc"}"
"{MERGEFIELD ALERT}"}

when Alert is empty, just using the IF is not above, because Word only
suppresses blank lines when they are composed of blank + at least one field
that's blank, and blank fields inserted as a result of an IF don't count. So

{ IF "{ MERGEFIELD ALERT }"= "GEN" "{INCLUDETEXT"C:\\Mer\\Gen.doc"}"
"{MERGEFIELD ALERT}"}{ MERGEFIELD ALERT }

would be suppressed when Alert is blank. But then if Alert is "RED", you
will get

REDRED

rather than just

RED

So again, you would need to do something like

{ IF "{ MERGEFIELD ALERT }"= "" ""
"{ IF "{ MERGEFIELD ALERT }" = "GEN"
"{INCLUDETEXT"C:\\Mer\\Gen.doc"}"
"{MERGEFIELD ALERT}
"}then stuff that should be on the next line

You might need

{ IF "{ MERGEFIELD ALERT }"= "" ""
"{ IF "{ MERGEFIELD ALERT }" = "GEN"
"{INCLUDETEXT"C:\\Mer\\Gen.doc"}
"
"{MERGEFIELD ALERT}
"}then stuff that should be on the next line

depending on what's at the end of gen.doc

Peter Jamieson

"Peter" wrote in message
...
Hi Peter,

Please bear with me on this since I am very green with the "IF"
statements.

I created a new document and put in the following single line:

{ IF "{ MERGEFIELD ALERT }"= "GEN" "{INCLUDETEXT"C:\\Mer\\Gen.doc"}"
"{MERGEFIELD ALERT}"}

I still get the blank field printed. I did check the Gen.doc itself and it
does not print the blank field.

Again, I am green at IF statements and perhaps I'm missing some things in
the document properties as well . . . and your comment: "but you do have
to
get the overall layout right" . . . I agree; perhaps I am overlooking
something.

I have been attempting a SP upgrade from SP1 to SP3. SP1 was a success but
SP3 is giving some difficulty in that it looks for DATA1.MSI for SP1 which
of
course does not exist on my original Office 2000 CD. Anyway, a different
matter altogether and I don't even know if the SP3 will address the "blank
field printing" issue.

Thanks again!

Peter



  #19   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Peter Peter is offline
external usenet poster
 
Posts: 111
Default Word mailmerge how to do multiple If statements

Hi Peter,

I guess for me, the confusion is where to place the information about the
actual fields in my Gen.doc within the If statement.

I have 4 different documents to begin with; Gen, Gen2, Gen3, Gen4. Within
each document I have 4 merge fields as so:

Name
Addr1
CPP

Sal

. . . . then the body text.

The field "Alert" does not appear in the document but is only used as
reference for type of letter.

So in your example of:

{ IF "{ MERGEFIELD ALERT }"= "" ""
"{ IF "{ MERGEFIELD ALERT }" = "GEN"
"{INCLUDETEXT"C:\\Mer\\Gen.doc"}"
"{MERGEFIELD ALERT}
"}then stuff that should be on the next line

I am confused about placement of the acutal data fields used in Gen, Gen2,
Gen3, Gen4, to suppress blank lines.

I will completely understand if you're getting frustrated with trying to get
the concept through my thick skull . . . so feel free to throw your hands up
and proclaim "what an idiot!" . . . lol

Thanks again for your time Peter.

Peter


  #20   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

If you use Alt-F9 to show the field codes in each gen?.doc, you would see
something like

{ MERGEFIELD Name }
{ MERGEFIELD Addr1 }
{ MERGEFIELD CPP }

{ MERGEFIELD Sal }

. . . . then the body text.

Assuming you want each of those MERGEFIELD lines to be removed when they are
blank, you could use

{ IF { MERGEFIELD Name } = ""
"" "{ MERGEFIELD Name }
" }{ IF { MERGEFIELD Addr1 } = ""
"" "{ MERGEFIELD Addr1 }
" }{ IF { MERGEFIELD CPP } = ""
"" "{ MERGEFIELD CPP }
" }

{ IF { MERGEFIELD Sal } = ""
"" "{ MERGEFIELD Sal }
" }
. . . . then the body text.

As I've probably said before, each of the pairs of {} need to be the special
field braces you can insert using ctrl-F9. Everything else is plain text. It
doesn't really matter how you lay out the IF fields as long as there's a
paragraph mark immediately after the { MERGEFIELD } in the result and the
following text follows straight on. e.g. you can use

{ IF { MERGEFIELD Name } = "" "" "{ MERGEFIELD Name }
" }{ IF { MERGEFIELD Addr1 } = "" "" "{ MERGEFIELD Addr1 }
" }{ IF { MERGEFIELD CPP } = "" "" "{ MERGEFIELD CPP }
" }

but not

{ IF { MERGEFIELD Name } = "" "" "{ MERGEFIELD Name }" }{ IF { MERGEFIELD
Addr1 } = "" "" "{ MERGEFIELD Addr1 }" }{ IF { MERGEFIELD CPP } = "" "" "{
MERGEFIELD CPP }" }

or

{ IF { MERGEFIELD Name } = "" "" "{ MERGEFIELD Name }
" }
{ IF { MERGEFIELD Addr1 } = "" "" "{ MERGEFIELD Addr1 }
" }
{ IF { MERGEFIELD CPP } = "" "" "{ MERGEFIELD CPP }
" }

(I usually do it the first way because it has more chance of getting through
these newsgroups unchanged)

Peter Jamieson


"Peter" wrote in message
...
Hi Peter,

I guess for me, the confusion is where to place the information about the
actual fields in my Gen.doc within the If statement.

I have 4 different documents to begin with; Gen, Gen2, Gen3, Gen4. Within
each document I have 4 merge fields as so:

Name
Addr1
CPP

Sal

. . . . then the body text.

The field "Alert" does not appear in the document but is only used as
reference for type of letter.

So in your example of:

{ IF "{ MERGEFIELD ALERT }"= "" ""
"{ IF "{ MERGEFIELD ALERT }" = "GEN"
"{INCLUDETEXT"C:\\Mer\\Gen.doc"}"
"{MERGEFIELD ALERT}
"}then stuff that should be on the next line

I am confused about placement of the acutal data fields used in Gen, Gen2,
Gen3, Gen4, to suppress blank lines.

I will completely understand if you're getting frustrated with trying to
get
the concept through my thick skull . . . so feel free to throw your hands
up
and proclaim "what an idiot!" . . . lol

Thanks again for your time Peter.

Peter






  #21   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Peter Peter is offline
external usenet poster
 
Posts: 111
Default Word mailmerge how to do multiple If statements

Peter!

Thanks so much! . . . you've cleared up the fog that's been bugging me for
the past few days and got me up at 3:30am this morning . . .

Really appreciate all your efforts and putting up with my "not just getting
it".

I have modified all my documents, Gen, Gen2, Gen3, Gen4, and then tested a
couple of hundred letters. They all turned out great. I required a date to be
right justified on the same line as the Name merge, so played around with
that and got the results I required.

http://img.photobucket.com/albums/v2...rout/Merge.jpg

Have a great day, I know I am with the work you've save me :-)

And a big thanks to you as well Ed and Doug . . .

Peter


  #22   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Ed Ed is offline
external usenet poster
 
Posts: 217
Default Word mailmerge how to do multiple If statements

Hi Peter,

Glad Peter and yourself got it sorted.

And Hi Peter J,

You are more confident than I am :-)


I rest my case.

Regards.

Ed


"Peter" wrote:

Peter!

Thanks so much! . . . you've cleared up the fog that's been bugging me for
the past few days and got me up at 3:30am this morning . . .

Really appreciate all your efforts and putting up with my "not just getting
it".

I have modified all my documents, Gen, Gen2, Gen3, Gen4, and then tested a
couple of hundred letters. They all turned out great. I required a date to be
right justified on the same line as the Name merge, so played around with
that and got the results I required.

http://img.photobucket.com/albums/v2...rout/Merge.jpg

Have a great day, I know I am with the work you've save me :-)

And a big thanks to you as well Ed and Doug . . .

Peter


  #23   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Pearl Pearl is offline
external usenet poster
 
Posts: 7
Default Word mailmerge how to do multiple If statements

Thank you Peter, that should be enough for my needs at present. I did try it
out in Word / Excel 2000 and OK, the mail merge process is different to
Office 2003, but it worked all right. Tried several times to print out the If
statement and kept getting the result rather than the field codes but managed
to get it to print out all right in the end. I've learned so much more about
Word/mail merge in the past few days. Thank u all for your help, it's much
appreciated. :-)

"Peter Jamieson" wrote:

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








Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
if statements with dates in mailmerge walkerh Mailmerge 3 April 9th 07 06:17 PM
How do I insert multiple hyperlinks in if, then, else statements? QUCJ Microsoft Word Help 0 September 21st 05 01:52 PM
How do i use multiple IF statements in word 2000? dg Mailmerge 1 August 18th 05 06:24 AM
MERGE: Can I have multiple SET statements based on one IF Bill Anderson Mailmerge 1 February 24th 05 06:03 AM
MERGE: Can I have multiple SET statements based on one IF Bill Anderson Mailmerge 0 February 24th 05 01:27 AM


All times are GMT +1. The time now is 02:28 PM.

Copyright ©2000 - 2023, Jelsoft Enterprises Ltd.
Copyright 2004-2023 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"