AND OR in Merge Fields

K

Kit Truong

I've got Merge fields in Word 2000 from an Access Database

I'm trying to add conditionals to my merge fields, does any know the syntax?

For example, using the built in merge fields in word, I can get a statement
like {If FIELD1="BLAH" "BLAH" ""}

But now, I want to add a conditional. Something like {If FIELD1="BLAH" OR
FIELD2="BLAH" "BLAH" ""}

Thanks
 
P

Peter Jamieson

1. I know you are just giving examples, but do be careful with the IF field
syntax:
a. Despite what some examples may show, you are generally better off using

{ IF { MERGEFIELD field1 }
or
{ IF { REF field1 }
than
{ IF field1
or if you are testing string values, use
{ IF "{ MERGEFIELD field1 }"
or
{ IF "{ REF field1 }"

b. always have a space either side of the comparison operator:
{ IF "{ MERGEFIELD field1 }" = "BLAH"

2. In answer to the question you actually asked, suppose you want

{If FIELD1="BLAH" OR
FIELD2="BLAH" "BLAH" ""}

you can either use the obvious nested IF:

{ IF "{ MERGEFIELD FIELD1 }" = "BLAH"
"BLAH"
"{ IF "{ MERGEFIELD FIELD2 }" = "BLAH"
"BLAH"
"" }" }

For
{If FIELD1="BLAH" AND
FIELD2="BLAH" "BLAH" ""}
you could use


{ IF "{ MERGEFIELD FIELD1 }" = "BLAH"
"{ IF "{ MERGEFIELD FIELD2 }" = "BLAH"
"BLAH" "" }"
"" }
or you can think in terms of generating 0/1 values using COMPARE fields,
then using {=} fields with "and" and "or" functions to test the results,
nested within an { IF } field.

There are limits to the level of nesting (20 I think)

Alternatively, you may be able to use Access queries that use iif functions
etc. to do the same thing and use the queries as the data source for your
merge.
 

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