Using IF to add a character

A

Asinger

I'm not sure if an IF rule is the right way to do this. I am creating a
Directory Merge, a list of names/addresses/phones/email. Some people have
more than one phone (e.g., home and cell). I would like the phones to be on
the same line, formatted as follows:

505-555-5555 / 505-555-6666

I right clicked the merge field for the second phone number shown above and
chose Edit Field. I selected the "Text to be inserted after:" check box and
entered space / space (where "space" is an actual space, not the word space).
This works great as long as there is always a value in the first phone number
field (I thought there would be but I have some records where there is only a
cell, the second phone number field, and no home phone, the first phone
number field). So instead of looking like the above example, I get this in
that case:

/ 505-555-6666

I think I need to add the spaces and slash after the first phone number
field, but I only want those characters to be used when the second phone
number field is not blank. Is that right? If so, can someone help me with
formatting the IF rule?

PART 2: What is the difference with inserting rules using the Rules
drop-down in the Ribbon versus right clicking a merge field and choosing Edit
Field? When should I use one over the other - or does it matter?

Thanks!
 
D

Doug Robbins - Word MVP

Use the following field construction:

{ IF { MERGEFIELD Home } <> "" "{ IF { MERGEFIELD Cell } <> "" "{ MERGEFIELD
Home } / { MERGEFIELD Cell }" "{ MERGEFIELD Home }" }" "{ MERGEFIELD
Cell }" }

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
 
A

Asinger

Doug - I understand about using Ctrl-F9 to produce the brackets. When I do
that, Word auto-inserts two spaces so that if I begin typing, my entry is
preceded and ended with a space (after/before open/close brackets). Your
entry seems to have the spaces too - can you just confirm for me that the
spaces are necessary? Also, do I type this directly in my merge document, and
where should I type it with respect to the merge fields? Thanks very much.
April
 
G

Graham Mayor

The spaces are not *required*, but as Word's insert field adds them, they
are best inserted for standardisation (e.g. you may wish to use replace on a
document so it helps if all are inserted the same way).
i.e.
{ MERGEFIELD Home }
and
{MERGEFIELD Home}
will both work equally well.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
P

Peter Jamieson

Just to add a couple of obscure details to Graham's comment
a. in the very early versions of Windows Word, Word did /not/ insert those
extra spaces automatically. I think those extra spaces arrived in Word 6.
a. there are at least two places where having a space before the closing
brace makes a difference:

{ MACROBUTTON mymacro mytext }blah
displays
mytext blah

whereas

{ MACROBUTTON mymacro mytext}blah
displays
mytextblah

and similarly

{ EQ \l(1,2,3) }blah
displays
1,2,3 blah

whereas
{ EQ \l(1,2,3)}blah
displays
1,2,3blah

There could be others, but for example SET and QUOTE fields do not behave
this way.

Peter Jamieson
 

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