Some complicated merge codes

M

Michelle

I am merging data from a database to a Word document.

I have to merge some names to a place in the document to look like this:

John Smith, Mary Smith, Bob Jones, Fred Jones, Jane Do
(let's call them Name1, Name2, Name3, Name4, Name 5)

Trouble is, I don't know in advance how many names I will have - the
possibilities are 1-5 names.

So, I need a statement that says:
Name1
If Name2 exists, put a comma after Name1
If Name3 exists, put a comma after Name2
If Name4 exists, put a comma after Name3
If Name5 exists, put a comma after Name4

Does anyone know how to do this?

Thanks.
 
S

Suzanne S. Barnhill

Each merge field will need to be embedded in an IF field and followed by a
comma. You can use it as the FalseText as follows:

{ IF { MERGEFIELD Name1 } = "" "" "{ MERGEFIELD Name1 }," }

Or as the TrueText as follows:

{ IF { MERGEFIELD Name1 } <> "" "{ MERGEFIELD Name1 }," }

In the second instance, no FalseText is required.
 
M

Michelle

Thanks so much Suzanne - that didn't actually do what I wanted, but it gave
me the idea to put the comma and a space+ in front of a name, thusly:
{ IF { MERGEFIELD Name1 } <> "" ", { MERGEFIELD Name1 }" "" }

That did the trick.
 
S

Suzanne S. Barnhill

Ah, right, good logic. I didn't actually test it, and I find that all mail
merges are pretty much trial and error, especially those involving
conditional fields!
 

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