MS Office Forum / Word / Mailmerge and Fax / May 2006
If then else question
|
|
Thread rating:  |
Michelle - 24 May 2006 02:57 GMT Can somebody help me with the correct syntax for the following:
If NAME2 is blank Then NAME1description + ",and" Else NAME1description
Doug Robbins - Word MVP - 24 May 2006 04:47 GMT { 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.
 Signature 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
> Can somebody help me with the correct syntax for the following: > > If NAME2 is blank > Then NAME1description + ",and" > Else NAME1descript Michelle - 25 May 2006 00:25 GMT 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!
> { IF { MERGEFIELD NAME2 } = "" "{ MERGEFIELD NAME1description }, and " "{ > MERGEFIELD NAME1descript }" } [quoted text clipped - 6 lines] > > Then NAME1description + ",and" > > Else NAME1descript Doug Robbins - Word MVP - 25 May 2006 05:55 GMT 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.
 Signature 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
> Thanks for your prompt reply, but unfortunately, I now understand this is > not [quoted text clipped - 31 lines] >> > Then NAME1description + ",and" >> > Else NAME1descript Michelle - 25 May 2006 18:59 GMT 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
> 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. Doug Robbins - Word MVP - 25 May 2006 20:55 GMT You must have some uneeded spaces in the field construction some where.
 Signature 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
> That was the first thing I tried - the result was spaces before the comma > like this: [quoted text clipped - 4 lines] >> the >> mergefield construction. Simply have it as text in the document. Michelle - 25 May 2006 21:10 GMT 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.
> You must have some uneeded spaces in the field construction some where. Doug Robbins - Word MVP - 25 May 2006 23:30 GMT 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
 Signature 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
> No, unfortunately, they are not uneeded: > [quoted text clipped - 15 lines] > >> You must have some uneeded spaces in the field construction some where. Michelle - 26 May 2006 00:40 GMT 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?
> 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 [quoted text clipped - 12 lines] > > Note that there is no space between the } and the { IF Doug Robbins - Word MVP - 26 May 2006 05:16 GMT 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?
 Signature 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
> 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 [quoted text clipped - 23 lines] >> >> Note that there is no space between the } and the { IF Michelle - 26 May 2006 19:30 GMT It's between the semicolon and the first letter of the following name
> 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? Doug Robbins - Word MVP - 26 May 2006 21:27 GMT 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
 Signature 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
> It's between the semicolon and the first letter of the following name > >> 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? Michelle - 26 May 2006 23:22 GMT 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.
> 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: [quoted text clipped - 6 lines] > Name5 } = "" "" ";{ MERGEFIELD Name5 }, { MERGEFIELD Name5Description }" }, > and Michelle - 26 May 2006 23:28 GMT 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.
|
|
|