IF statement in a merge

K

Kathy Webster

Hmm...how do I explain this...

I want the merge document to include the {MERGEFIELD Signatory} if and only
if...

1. {MERGEFIELD SigBarNo} does not equal {MERGEFIELD A1Bar} and
2. {MERGEFIELD SigBarNo} does not equal {MERGEFIELD A2Bar} and
3. {MERGEFIELD SigBarNo} does not equal {MERGEFIELD A3Bar}

If {MERGEFIELD SigBarNo} equals any of the above, I want {MERGEFIELD
Signatory} to be omitted.

TIA and happy holidaze,
Kathy
 
P

Peter Jamieson

Try

{ IF "{ MERGEFIELD SigBarNo }" <> "{ MERGEFIELD A1Bar }"
"{ IF "{ MERGEFIELD SigBarNo }" <> "{ MERGEFIELD A2Bar }"
"{ IF "{ MERGEFIELD SigBarNo }" <> "{ MERGEFIELD A3Bar }"
"{ MERGEFIELD Signatory }" "" }" "" }" "" }

where all the {} are the special field code braces you can enter using
ctrl-F9 and everything else is plain text.
(It can all be on one line if you want).
 
K

Kathy Webster

I tried to no avail. I am aware of the Ctrl-F9 code brace technique.
I triple checked my work before writing back.
Do spaces before/after brackets matter?
 
K

Kathy Webster

Figured it out. Took off quotes on all except "{MERGEFIELD Signatory}" and
it worked. Thank you!
 
P

Peter Jamieson

Do spaces before/after brackets matter?

If you lay it out the way I did you should be OK.The statement could
typically be simplified or reduced in various ways, e.g. drop the quotes
around the MERGEFIELD fields, especially if the MERGEFIELD rresults are
always numeric and are always represented the same way, e.g. "2" is always
"2" and not "02"

{IF "{MERGEFIELD SigBarNo}" <> "{MERGEFIELD A1Bar}"
"{IF "{MERGEFIELD SigBarNo}" <> "{MERGEFIELD A2Bar}"
"{IF "{MERGEFIELD SigBarNo}" <> "{MERGEFIELD A3Bar}"
"{MERGEFIELD Signatory}" ""}" ""}" ""}

should also be OK.

What hapens if you start with a really simple expression, e.g.

{ IF "{ MERGEFIELD SigBarNo }" <> "{ MERGEFIELD A1Bar }" "{ MERGEFIELD
Signatory }" "" }

or

{ IF "{ MERGEFIELD SigBarNo }" = "{ MERGEFIELD A1Bar }" "" "{ MERGEFIELD
Signatory }" }


? Does either of them work as you expect? If not, can you use Alt-F9 to
reveal the field codes, select each of the inner mergefield fields in turn,
and use the right-click menu to toggle field codes? You should then be able
to see the inner results and make sure they are as you expect.

Do you have any SKIPIF fields in your mail merge main document?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top