Link to home
Start Free TrialLog in
Avatar of loybob
loybobFlag 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 -
Avatar of DB-aha
DB-aha

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

Open in new window

Avatar of loybob

ASKER

That doesn't work because they are merge fields for a mail merge document.  It's a field from MS Access.
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?
Avatar of 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 -
Did you try:

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

ASKER

There is no command (else) - that's just to show that I need something there.
ASKER CERTIFIED SOLUTION
Avatar of loybob
loybob
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of loybob

ASKER

I figured it out myself.