Word – How to compare many values with an OR statement in Word mergefields

microsoft wordmicrosoft-word-2013

What I want to do is:

{ IF v1 = 0 OR v2 = 0 "Lorem Ipsum.." }

How to write an OR in Word mergefield syntax?

I'm asking especially for Word 2013 – I think the syntax has changed in 2013.

Best Answer

If the v1, v2 are MERGE fields, in the general case you need { MERGEFIELD v1 } and { MERGEFIELD v2 }. You can then do an OR using a construct like this:

{ IF { =OR({ COMPARE { MERGEFIELD v1 } = 0 },{ COMPARE { MERGEFIELD v2 = 0 }) } = 0 "Lorem Ipsum.." }

(As usual, all the { } have to be the special field code brace pairs that you can insert on Windows Word using ctrl-F9.

Or for short result texts you can use a numeric picture switch to produce the correct result, e.g.

{ =OR({ COMPARE { MERGEFIELD v1 } = 0 },{ COMPARE { MERGEFIELD v2 = 0 }) }) \#"'';'';'Lorem Ipsum..'" }

For more comparands you need to nest the ORs

In this case you could also do stuff such as

{ IF { =ABS({ MERGEFIELD v1 })+ABS({ MERGEFIELD v2 }) } = 0 "Lorem Ipsum.. }

FWIW I do not believe the syntax has changed in Word 2013 in this area, but if you have an example of such a difference, please share!