If then else question

M

Michelle

Can somebody help me with the correct syntax for the following:

If NAME2 is blank
Then NAME1description + ",and"
Else NAME1description
 
D

Doug Robbins - Word MVP

{ IF { MERGEFIELD NAME2 } = "" "{ MERGEFIELD NAME1description }, and " "{
MERGEFIELD NAME1descript }" }

You must use Ctrl+F9 to insert each pair of field delimiters { } and Alt+F9
to toggle 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
 
M

Michelle

Thanks for your prompt reply, but unfortunately, I now understand this is not
the result I want, after all. I have 5 mergefields for names ("John Smith",
etc) and 5 merge fields for descriptions ("an individual") but don't know in
advance how many the record will actually contain.

This is what I got using your suggestions:
JOHN SMITH, an individual
MARY SMITH, an individual
an individual, and
an individual, and
an individual, and
an individual, and

Here's the result I really need:
JOHN SMITH, an individual
MARY SMITH, an individual, and

So, I always need ", and" after the last name.

Is there a way to do this? Sorry about my confused mind!
 
D

Doug Robbins - Word MVP

If you always need ", and" after the last name, do not make it part of the
mergefield construction. Simply have it as text in the document.

--
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

Michelle

That was the first thing I tried - the result was spaces before the comma
like this:

JOHN SMITH, an individual; MARY SMITH, an individual ,and
 
D

Doug Robbins - Word MVP

You must have some uneeded spaces in the field construction some where.

--
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

Michelle

No, unfortunately, they are not uneeded:

Here's what I have as merge codes (and I will add ", and" per your
suggestion):

Name1, Name1description Name2, Name2 description Name3 Name3,
description Name4, Name4 description Name 5, Name 5 description, and

This works fine if indeed 5 names are merged. But if any less than 5 are
merged, there are spaces before ", and".

So if there is only one name in the record, the result is:
JOHN SMITH, an individual , and

That's why the ", and" needs to be in the mergecode.

Hope this is clear and that you have a solution.
 
D

Doug Robbins - Word MVP

You still need the If...then...Else... fields to check for data in Name2,
Name3, Name4 and Name5. If there is not data insert nothing, if there is
data, insert that data preceeded by whatever it is that you want to separate
it from the previous item.

The construction will be

{ MERGEFIELD Name1 }, { MERGEFIELD Name1Description }{ IF { MERGEFIELD
Name2 } = "" "" "; { MERGEFIELD Name2 }, { MERGEFIELD
Name2Description }" }{IF { MERGEFIELD Name3 } = "" "" "; { MERGEFIELD
Name3 }, { MERGEFIELD Name3Description }" }{IF { MERGEFIELD Name4 } = "" ""
"; { MERGEFIELD Name4 }, { MERGEFIELD Name4Description }" }(IF { MERGEFIELD
Name5 } = "" "" "; { MERGEFIELD Name5 }, { MERGEFIELD Name5Description }" },
and

Note that there is no space between the } and the { IF

--
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

Michelle

Thanks SO much - that was great. There is only one teeny thing left -
somehow I am getting 2 spaces between each record, and I'd really like only
one. I tried playing around with the quotes, but obviously don't understand
how to do it. Can you show me please?
 
D

Doug Robbins - Word MVP

Is that two spaces between the semicolon and the first letter of the
following name? Or, do you mean each record in the data source?

--
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

Doug Robbins - Word MVP

Maybe there is a space before the name in the data source. But you can
always remove the space after the semi-colon in the field construction:

{ MERGEFIELD Name1 }, { MERGEFIELD Name1Description }{ IF { MERGEFIELD
Name2 } = "" "" ";{ MERGEFIELD Name2 }, { MERGEFIELD
Name2Description }" }{IF { MERGEFIELD Name3 } = "" "" ";{ MERGEFIELD
Name3 }, { MERGEFIELD Name3Description }" }{IF { MERGEFIELD Name4 } = "" ""
";{ MERGEFIELD Name4 }, { MERGEFIELD Name4Description }" }(IF { MERGEFIELD
Name5 } = "" "" ";{ MERGEFIELD Name5 }, { MERGEFIELD Name5Description }" },
and


--
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

Michelle

Sorry, I didn't use the semi-colon because it is built into the description.
I keep playing with those quotes but either I get two spaces or none. Still
hoping you have a solution. Thanks.
 
M

Michelle

Ok, now I figured it out and removed the space where the semi-colon WOULD
have been had I used it! I was off on the wrong track with the quotes.

That wraps it up. Thank you again very much for your patience and knowledge.
 

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