If statements

D

dleo

Is there a way to use IF statements within a mail merge? I'm using an excel
file as my data source. I have the prefix merge field, but about half of the
data entries have none. So when I merge in Word, the prefix field is skipped
(as it should), but I still get that space in between where the prefix would
go and the person's first name. Is there some sort of IF field where I could
basically say "if there IS a prefix put in the space, but if there isn't,
don't put a space."

I hope that makes sense.
 
D

Doug Robbins - Word MVP

Use the follwing field construction

{ IF { MERGEFIELD Prefix } <> "" "{ MERGEFIELD Prefix } { MERGEFIELD
FirstName }" "{ MERGEFIELD FirstName } }

You may need to change the Prefix and FirstName to the actual names of your
fields.

You must use Ctrl+F9 to insert each pair of field delimiters { } and you use
Alt+F9 to toggle off their display.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
D

dleo

It didn't work. Well, the data merges successfully, but there is no space in
front of the first name no matter if there is a prefix or not. Also, my first
name field is 2 words (FIRST NAME) so maybe that has something to do with it.
 
D

Doug Robbins - Word MVP

I missed a closing quote when typing the construction

{ IF { MERGEFIELD Prefix } <> "" "{ MERGEFIELD Prefix } { MERGEFIELD
"First_Name" }" "{ MERGEFIELD "First_Name" }" }

If the name of the field that contains the first name is two words,. use the
construction as shown above.


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
M

macropod

Hi Doug,

I'd be inclined to use a simpler construction:
{IF{MERGEFIELD Prefix}<> "" "{MERGEFIELD Prefix} "}{MERGEFIELD "First_Name"}

For the OP, the steps to reproduce this would be:
.. copy your «Prefix» field and paste it into your document ahead of the «First_Name» field, thus -
«Prefix»«Prefix»«First_Name»;
.. select the two «Prefix» fields and press Ctrl-F9 to enclose them in a new field, thus -
{«Prefix»«Prefix»}«First_Name»;
.. fill in around the new field braces thus, paying careful attention to the spacing -
{IF«Prefix»<> "" "«Prefix» "}«First_Name»;
.. position the cursor anywhere in this field and press F9 to update it;
.. run the mailmerge.
 
D

dleo

Thank you macropod, your method is a lot easier. It works great!

Thanks again,
dleo

macropod said:
Hi Doug,

I'd be inclined to use a simpler construction:
{IF{MERGEFIELD Prefix}<> "" "{MERGEFIELD Prefix} "}{MERGEFIELD "First_Name"}

For the OP, the steps to reproduce this would be:
.. copy your «Prefix» field and paste it into your document ahead of the «First_Name» field, thus -
«Prefix»«Prefix»«First_Name»;
.. select the two «Prefix» fields and press Ctrl-F9 to enclose them in a new field, thus -
{«Prefix»«Prefix»}«First_Name»;
.. fill in around the new field braces thus, paying careful attention to the spacing -
{IF«Prefix»<> "" "«Prefix» "}«First_Name»;
.. position the cursor anywhere in this field and press F9 to update it;
.. run the mailmerge.

--
Cheers
macropod
[MVP - Microsoft Word]


Doug Robbins - Word MVP said:
I missed a closing quote when typing the construction

{ IF { MERGEFIELD Prefix } <> "" "{ MERGEFIELD Prefix } { MERGEFIELD
"First_Name" }" "{ MERGEFIELD "First_Name" }" }

If the name of the field that contains the first name is two words,. use the construction as shown above.


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

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