AND and OR in the same IF THEN statement

J

Jonathan Crow

I am trying to combine AND and OR statements in an if then
statement.

I am trying to test for
if Value_1 is true and (Value_2 is true then put one
thing, or if Value_2 is true put a second thing, or if
Value_3 is true put a third thing).

The code I wrote is:
{IF { MERGEFIELD Code1 } = "A" "{IF { MERGEFIELD Code2 }
= "2a" "A2a" "{ IF {MERGEFIELD Code2 } = "2b" "A2b" "{If
{MERGEFIELD Code2 } = "2c" "A2c" "" }" }" }" "" }

The only result I get is if the value in Code1 = A and the
value in Code2 = 2c, but the result I get is A2a. Any
ideas what I am doing wrong?

Thanks,
Jonathan
 
C

Cindy Meister -WordMVP-

Hi Jonathan,

I don't see anything that should be causing what you
describe, but...
1) Are you certain you used Ctrl+F9 for EACH set of field
brackets { }?
2) If you put "quotes" around the Mergefields to the left of
the =, does that make any difference?
3) Copy each IF field, from the innermost level to the
outermost, one at a time, outside the nested field set and
test if it returns the correct value. Then you can narrow
down where the problem is occurring.
I am trying to test for
if Value_1 is true and (Value_2 is true then put one
thing, or if Value_2 is true put a second thing, or if
Value_3 is true put a third thing).

The code I wrote is:
{IF { MERGEFIELD Code1 } = "A" "{IF { MERGEFIELD Code2 }
= "2a" "A2a" "{ IF {MERGEFIELD Code2 } = "2b" "A2b" "{If
{MERGEFIELD Code2 } = "2c" "A2c" "" }" }" }" "" }

The only result I get is if the value in Code1 = A and the
value in Code2 = 2c, but the result I get is A2a. Any
ideas what I am doing wrong?

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jan
24 2003)
http://www.mvps.org/word

This reply is posted in the Newsgroup; please post any follow
question or reply in the newsgroup and not by e-mail :)
 
J

Jonathan Crow

Cindy,

I discovered that Word saw the value 2a as a number. So,
2a was equal to 2b was equal to 2c. So, I just took the 2
out of the excel spreadsheet and it worked fine.

Argh word and numbers.

Thanks,
Jonathan
 
C

Cindy Meister -WordMVP-

Hi Jonathan,

In this case, put *both sides* of the comparison equation in
quotes: "2" = "2a" is NOT equal.

With Word IF fields, you need to you quotes very
conscientiously. Where there's an uncertainty whether
numbers or strings are being compared, be sure to use quotes
to enforce string comparisons, and not use quotes if you
want to do something numerical. It won't enforce everything,
but it will help :)
I discovered that Word saw the value 2a as a number. So,
2a was equal to 2b was equal to 2c. So, I just took the 2
out of the excel spreadsheet and it worked fine.

Argh word and numbers.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jan
24 2003)
http://www.mvps.org/word

This reply is posted in the Newsgroup; please post any
follow question or reply in the newsgroup and not by e-mail
:)
 

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