View Single Post
  #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