How do I use IF THEN comparing 2 merge fields?

A

AFN

I'm doing a mail merge with Word from Office XP. I have these fields in my
datasource:
FirstName
LastName
AccountName

Sometimes AccountName is the same as FirstName + " " + LastName. But other
times, the AccountName is a business name that is totally different than a
person's name.

I want to print the AccountName field only if it is different than the
person's [first and last name]. But the If/Then dialog window doesn't give
me the option to compare one datasource field (AccountName) to the
concatenation of two other data fields (FirstName + " " + LastName) and
insert a datasource field (AccountName) if they are not equal to each other,
else insert nothing. How do I do this? Thanks.
 
P

Peter Jamieson

Insert the field directly using ctrl-F9 for the special braces and using
Alt-F9 to toggle between "field codes" and field results".

Then you can do something lke:

{ MERGEFIELD FIrstName } { MERGEFIELD LastName }
{ IF "{ MERGEFIELD AccountName }" = "{ MERGEFIELD FirstName } { MERGEFIELD
LastName }"
""
"{ MERGEFIELD AccountName }" }
 
A

AFN

That works beautifully! Thanks. I didn't realize that you were allowed to
put quotes around things.

But how can I suppress the whole line if there is nothing to display (your
empty quotes below)? I was reading that you have to encapsulate the line
break with Word 2002/XP, but I don't know how to reveal or encapsulate it.

Again, thanks.


Peter Jamieson said:
Insert the field directly using ctrl-F9 for the special braces and using
Alt-F9 to toggle between "field codes" and field results".

Then you can do something lke:

{ MERGEFIELD FIrstName } { MERGEFIELD LastName }
{ IF "{ MERGEFIELD AccountName }" = "{ MERGEFIELD FirstName } { MERGEFIELD
LastName }"
""
"{ MERGEFIELD AccountName }" }

--
Peter Jamieson - Word MVP
Word MVP web site http://word.mvps.org/

AFN said:
I'm doing a mail merge with Word from Office XP. I have these fields in my
datasource:
FirstName
LastName
AccountName

Sometimes AccountName is the same as FirstName + " " + LastName. But other
times, the AccountName is a business name that is totally different than a
person's name.

I want to print the AccountName field only if it is different than the
person's [first and last name]. But the If/Then dialog window doesn't give
me the option to compare one datasource field (AccountName) to the
concatenation of two other data fields (FirstName + " " + LastName) and
insert a datasource field (AccountName) if they are not equal to each other,
else insert nothing. How do I do this? Thanks.
 
P

Peter Jamieson

But how can I suppress the whole line if there is nothing to display (your
empty quotes below)?

If what you want is

where the FirstName LastName & Accountname differ:

FirstName LastName
Accountname
further text

where the FirstName LastName & Accountname are the same:

FirstName LastName
further text

then try:

{ MERGEFIELD FIrstName } { MERGEFIELD LastName
}
{ IF "{ MERGEFIELD AccountName }" = "{ MERGEFIELD FirstName } { MERGEFIELD
LastName }"
""
"{ MERGEFIELD AccountName }" }Further text

You can put ordinary paragraph marks etc. inside the IF field results simply
by including the return inside the result text, e.g. if you have

a{ IF x = y "b" "b
" }c

then if x = y you should see

abc

and if x <>y you should see
ab
c

--
Peter Jamieson - Word MVP
Word MVP web site http://word.mvps.org/

AFN said:
That works beautifully! Thanks. I didn't realize that you were allowed to
put quotes around things.

But how can I suppress the whole line if there is nothing to display (your
empty quotes below)? I was reading that you have to encapsulate the line
break with Word 2002/XP, but I don't know how to reveal or encapsulate it.

Again, thanks.


Peter Jamieson said:
Insert the field directly using ctrl-F9 for the special braces and using
Alt-F9 to toggle between "field codes" and field results".

Then you can do something lke:

{ MERGEFIELD FIrstName } { MERGEFIELD LastName }
{ IF "{ MERGEFIELD AccountName }" = "{ MERGEFIELD FirstName } { MERGEFIELD
LastName }"
""
"{ MERGEFIELD AccountName }" }

--
Peter Jamieson - Word MVP
Word MVP web site http://word.mvps.org/

in
my
than
a
person's name.

I want to print the AccountName field only if it is different than the
person's [first and last name]. But the If/Then dialog window doesn't give
me the option to compare one datasource field (AccountName) to the
concatenation of two other data fields (FirstName + " " + LastName) and
insert a datasource field (AccountName) if they are not equal to each other,
else insert nothing. How do I do this? Thanks.
 

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