Mail Merge Question

I have a data source for a mail merge to pull from. Some of the people I have in the data source have an additional name on their account and some don't. When doing their address for mailing, I did figure out how to not display the additional name if it's blank but now I have another question. On the greeting line, I'd like it to say "Dear <Name> and <Additional Name>:" but only include the 'and <Additional Name>' if it contains something. How can I do that? I'm using Word 2016.

Thanks.
itgolferAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

GrahamSkanRetiredCommented:
You need to use an IF field to test for a for blank merge field and to show the word 'and' plus the field if it is not blank

Use Alt + F9 to toggle to show field codes. You can enter an empty field around the Selection using Ctrl+F9 and enter the field contents from the keyboard.

It should look like this:

Dear { MERGEFIELD Name }{ IF {  MERGEFIELD Additional_Name } = "" " and  {  MERGEFIELD Additional_Name } " }
itgolferAuthor Commented:
Thanks, Graham. When I tried to copy it to look like yours, just changing out the field names, it's still leaving all of the other text in it like the brackets and MERGEFIELD text. Can I not type in any of that information?
itgolferAuthor Commented:
Sorry, I missed your part about using Ctrl + F9 to get the other brackets. I have the below entered in but it seems like it's backwards. For those customers that have something in the AddlName field, it's just saying "Dear ComName" and for the customers that the AddlName field is blank, it's saying "Dear ComName and ". ComName is the field with the primary name in it.

Dear { MERGEFIELD ComName }{ IF {  MERGEFIELD AddlName } = "" " and  { MERGEFIELD AddlName } " }
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

GrahamSkanRetiredCommented:
Did you note that I had italicised the word 'look'? That is because in the comment I had only typed in the curly brackets that resemble the field delimiters. In the Word document, they must be inserted, either using Crtl+F9, or by inserting the whole field: Insert tab, Text group, Quick Parts dropdown, Field... item.

I have attached a sample document
MergeFields.docx
GrahamSkanRetiredCommented:
Sorry we cross-posted, so I hadn't read your latest comment
GrahamSkanRetiredCommented:
What you show looks right. If you are still having problems, save that bit and post it, so that we can test it here,
itgolferAuthor Commented:
No problem. I actually just copied and pasted from your document and I'm getting the same thing. Customer with only one name is getting the 'and' added and the customers with two names are not getting it.
itgolferAuthor Commented:
Should I upload the Word document?
GrahamSkanRetiredCommented:
I did test it, but I was a bit quick, so I'll test it again with more care.
GrahamSkanRetiredCommented:
Don't upload it until I have retested my example.
GrahamSkanRetiredCommented:
My original did work, but at some stage I dropped an empty pair of quotes. My apologies
Dear { MERGEFIELD ComName }{ IF {  MERGEFIELD AddlName } =] "" "" and  { MERGEFIELD AddlName } " }
itgolferAuthor Commented:
How did you add the ] after the equal sign? Did you manually type that into the Word document?
itgolferAuthor Commented:
OK, I think I've got it figured out now. The only issue I'm still having is if there is not a second customer name, it's displaying as "Dear Joe Smith  ," Is there a way to move that comma up at the end of the name if there isn't a second name? Thanks for your help.
GrahamSkanRetiredCommented:
Sorry for not answering sooner. I guess my evening started before yours. Sorry, too,  about the intrusive ']' (from my fat finger).

Are there spaces in the text? If any are necessary you can put them in the field like those surrounding the word 'and'. Any text outside the field will always show in the output.

Barring any more of my typos, I would expect the field complex to look like this:

Dear { MERGEFIELD ComName }{ IF {  MERGEFIELD AddlName } = "" "" and  { MERGEFIELD AddlName } " },
itgolferAuthor Commented:
No problem at all. I am at a loss now. I had and additional {MERGEFIELD AddlName} entry after your } " } followed by a comma. When I take that out, the secondary name doesn't show, even if it's in the source data. Would it help if I uploaded my test source data and Word document?
GrahamSkanRetiredCommented:
Yes. If you can upload it, that would help.
itgolferAuthor Commented:
Great, thanks. Here you go.
MergeTest.docx
MergeTest.xlsx
GrahamSkanRetiredCommented:
It might just be my system, but something weird was happening. The unwanted square bracket was visible and I couldn't delete it, but it didn't show up in the result.

I have tweaked the code by adding the missing "". The comma comes immediately after the field. This produces the right output, but I can see some of the data in non-preview mode.
MergeTest2.docx
itgolferAuthor Commented:
Thank you so much! I do have an extra space in between the word 'and' and the second name if there is one and a space after the second name and the comma. If there is only one name listed, it looks good. Are you seeing the same thing on your side?
GrahamSkanRetiredCommented:
Yes. Mine is the same. I will try to work out why the extra spaces are there.
GrahamSkanRetiredCommented:
There were some extra spaces between the quotes that include the word 'and' and the second instance of the AddName field.
MergeTest3.docx

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
itgolferAuthor Commented:
Thank you so much!!! I can't even tell you how huge this is to get over this hump. I really appreciate your time and patience. Have a great day!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Office

From novice to tech pro — start learning today.