• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1222
  • Last Modified:

If Then Else in Word 2007 mail merge

I have an SQL database that has three address tabs for members, work, home and po box.  Each member can select one tab as their preferred address, which is stored in the field Name_AddressPURPOSE.  Some members are associated with a company (NameCOMPANY) and have their mail addressed to them at work. Some members are associated with a company but have their mail sent to them at home.  I don't want the company  name to appear to those who have their mail sent to their home.

In the mail merge, I want it to show the Company name for those members that have their mail addressed to work, and to have no field nor a blank line if they have their mail addressed to home.  I did an if then else statement as follows:

{NameFULL_NAME}
{IF Name_AddressPURPOSE  = "Work Address" "{ MERGEFIELD NameCompany } " ""}
{MERGEFIELD Name_AddressFULL_ADDRESS}

However, it does not show the company name on any member when I preview the results, and has a blank line ie:

Mr S  Smith
 
Geelong-Barwon Heads Road
BARWON HEADS  VIC  3227

Any help appreciated!

0
Jedi2602
Asked:
Jedi2602
  • 3
  • 3
  • 3
2 Solutions
 
StellanRosengrenCommented:
Hi Jedi2602,
I think it should be:
{IF { MERGEFIELD Name_AddressPURPOSE } = "Work Address" "{ MERGEFIELD NameCompany } " ""}

Kind regards,
Stellan
0
 
Joanne M. OrzechManager, Document Services CenterCommented:
I think you need to put the hard return (^p) after the field code:{ MERGEFIELD NameCompany }^p

Then on the same line, you put the next field code.

{NameFULL_NAME}
{IF Name_AddressPURPOSE  = "Work Address" "{ MERGEFIELD NameCompany }[hit the enter key here] " ""}{MERGEFIELD Name_AddressFULL_ADDRESS}
0
 
Jedi2602Author Commented:
Thanks for the suggestions, however, now I get the word "MERGEFIELD" in front of the address, but still no Company Name.  I've attached a screen shot of the code (code.jpg) and a screen shot of the result
code.jpg
result.jpg
0
Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

 
StellanRosengrenCommented:
Hi Jedi2602,
What is the result if you try this?

{MERGEFIELD NameFULL_NAME}
{IF {MERGEFIELD Name_AddressPURPOSE} = "Work Address" "{MERGEFIELD NameCompany} " ""}
{MERGEFIELD Name_AddressFULL_ADDRESS}

Kind regards,
Stellan
0
 
Joanne M. OrzechManager, Document Services CenterCommented:
I guess I don't understand what you're trying to do.  If the Mergefield is the Work Address, what field do you want inserted?  If it is NOT the work address, what field do you want inserted?

Joanne Orzech
Word MVP
0
 
Jedi2602Author Commented:
Ok, thanks StellanRosengren, that extra "mergefield" did the trick!  I've attached some jpgs ... one of the successful code - I had to put the paragraph break in the actual field to make it suppress the blank line.  Works great, thanks for everyone's help!
success.jpg
Workaddress.jpg
homeaddress.jpg
0
 
Jedi2602Author Commented:
I had to copy and paste the curly brackets rather than just typing the curly bracket key on the keyboard.  Didn't seem to recognise it as a field until I did that.
0
 
Joanne M. OrzechManager, Document Services CenterCommented:
Glad to have been of assistance.

Thank you.

Joanne Orzech
Word MVP
0
 
StellanRosengrenCommented:
Always ready to help a Jedi!
Thanks for the grade.

Stellan
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 3
  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now