Avatar of loybob
loybob
Flag for United States of America asked on

Using an IF in a Mergefield in Word

I want to have an if statement in my Word mail merge document.  This is what I want:

IF {MERGEFIELD Prefix} = "Esq."  then
{MERGEFIELD FirstName} {MERGEFIELD LastName}, {MERGEFIELD Prefix}
else
{MERGEFIELD Prefix} {MERGEFIELD FirstName} {MERGEFIELD LastName}
End If

and there's a comma after the LastName in the second line and spaces in between the mergefields.

Can anyone give me the proper syntax for that?

Thank you -
Word Processors

Avatar of undefined
Last Comment
loybob

8/22/2022 - Mon
DB-aha

{IF prefix = "esq" "FirstName LastName Prefix" "Prefix FirstName LastName, "}

Open in new window

loybob

ASKER
That doesn't work because they are merge fields for a mail merge document.  It's a field from MS Access.
DB-aha

Just to be clear, you are creating a mail merge in Word that you want to link to an access database to select a series of fields?
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
loybob

ASKER
Yes, and the mail merge is working fine.  I have a field called Prefix in my Access database.  If is says "Mr.", I want the line in the mail merge document to be

Mr. John Smith          (after merge)
{MERGEFIELD Prefix} {MERGEFIELD FirstName} {MERGEFIELD LastName}        

If Prefix says "Esq." I want

John Smith, Esq.                (after merge)
{MERGEFIELD FirstName} {MERGEFIELD LastName}, {MERGEFIELD Prefix}                  

I can do this:
{IF {MERGEFIELD Prefix} = "Esq." "Yes" "No"}

I want this:
{IF {MERGEFIELD Prefix} = "Esq." {MERGEFIELD FirstName} {MERGEFIELD LastName}, {MERGEFIELD Prefix}  (else) {MERGEFIELD Prefix} {MERGEFIELD FirstName} {MERGEFIELD LastName}  }

I need some kind of separators or something -
DB-aha

Did you try:

{IF {MERGEFIELD Prefix} = "Esq." {MERGEFIELD FirstName}" "{MERGEFIELD LastName}, {MERGEFIELD Prefix}  (else) {MERGEFIELD Prefix}" "{MERGEFIELD FirstName}" "{MERGEFIELD LastName}", " }
loybob

ASKER
There is no command (else) - that's just to show that I need something there.
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER CERTIFIED SOLUTION
loybob

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
loybob

ASKER
I figured it out myself.