Share via

How do I use if...then...else conditional mail merge rule to create custom thank you letters with variable paragraphs, based on the thank-you letter field in the data file??

Anonymous
2013-06-24T20:24:50+00:00

I would like the logic to work like

"if [thank you field] = a, then insert text "one";   if [thank you field] = b, then insert text "two";  if [thank you field] = c, then insert text "three"; if [thank you field] = d, then insert text "four"; etc.

and would like to use multiple instances of that logic to change text in three or more places in the letter, based on the value in the [thank you field]

Thanks

M

Microsoft 365 and Office | Word | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Doug Robbins - MVP - Office Apps and Services 323K Reputation points MVP Volunteer Moderator
2013-06-25T07:01:01+00:00

Using Ctrl+F9 to insert each pair of field delimiters{}, use

{ IF { MERGEFIELD "Thank you field } = "a" { INCLUDETEXT "Drive:\Path\Filename for text one"}

{ IF { MERGEFIELD "Thank you field } = "b" { INCLUDETEXT "Drive:\Path\Filename for text two"}

{ IF { MERGEFIELD "Thank you field } = "c" { INCLUDETEXT "Drive:\Path\Filename for text three"} { INCLUDETEXT "Drive:\Path\Filename for text four"} } } }

Use Alt+F9 to toggle off the display of the field codes.

Was this answer helpful?

0 comments No comments

9 additional answers

Sort by: Most helpful
  1. Anonymous
    2016-10-03T11:43:50+00:00

    Sorry - I did not understand the meaning of INCLUDETEXT construct. Assume it is to include something from another document?

    Yes, there is a space after Member so that works, and the field is actually 7 characters long, but I am only interested in the first 3 digits, hence my use of "503*". I think that part is working okay.

    I am running a membership report and the Excel spreadsheet that I have merged with my report is generated by someone else, so I am trying to use it as is and not have to manipulate it every time we get it.

    I want to interrogate the Member_ field and based on values in the first 3 characters of it, print something on the report.

    I tried to format it like this:

    { IF {MERGEFIELD Member_} = "503*"  "Epsilon - Syracuse University" ""}

    { IF {MERGEFIELD Member_} = "562*"   "Beta Tau - University of Florida" ""}

    { IF {MERGEFIELD Member_} = "571*"   "Gamma Zeta - Northern Illinois University" ""}

    And what I woudl get sometimes is extra text in the print field (like it was left over from the previous record. Does that make sense?? That is why I was trying to figure out if I needed to use a nested If..The construct.

    Was this answer helpful?

    0 comments No comments
  2. Paul Edstein 82,861 Reputation points Volunteer Moderator
    2016-10-03T04:28:18+00:00

    One reason you might get unpredictable results with:

    { IF {MERGEFIELD Member_} = "503*"  {INCLUDETEXT "Epsilon - Syracuse University"}

    { IF {MERGEFIELD Member_} = "562*"  {INCLUDETEXT "Beta Tau - University of Florida"}

    { IF {MERGEFIELD Member_} = "571*"  {INCLUDETEXT "Gamma Zeta - Northern Illinois University"}

    is that you've omitted the file paths. These should be included, with double backslashes for the separators. For example:

    { IF {MERGEFIELD Member_} = "503*"  {INCLUDETEXT "Drive:\Path\Epsilon - Syracuse University"}

    { IF {MERGEFIELD Member_} = "562*"  {INCLUDETEXT "Drive:\Path\Beta Tau - University of Florida"}

    { IF {MERGEFIELD Member_} = "571*"  {INCLUDETEXT "Drive:\Path\Gamma Zeta - Northern Illinois University"}

    Another possibility relates to your use of *. That is a wildcard and tells Word to output the same INCLUDETEXT field for any Member whose designation matches the first three digits, regardless of how many characters follow those first 3. Thus, if you had:

    { IF {MERGEFIELD Member_} = "503*"  {INCLUDETEXT "Drive:\Path\Epsilon - Syracuse University"}

    { IF {MERGEFIELD Member_} = "5035"  {INCLUDETEXT "Drive:\Path\Beta Tau - University of Florida"}

    you'd get both letters for any Member whose number begins with 503. It might be worthwhile including the {MERGEFIELD Member_} field in the mailmerge main document on its own so you can see what it's outputting with the problem records.

    Was this answer helpful?

    0 comments No comments
  3. Doug Robbins - MVP - Office Apps and Services 323K Reputation points MVP Volunteer Moderator
    2016-10-03T04:14:57+00:00

    This is a limit on the depth of the field nesting, but it would not apply to the second method that you are using.

    Do you have a space after the r of Member in the field name in the data source?

    Does the data in that field actually end with an asterisk, or is that intended to signify any other character in the position of the fourth character.

    If the * signifies any other character, assuming that you are using Excel as the data source it might be best to add another field that you populate with Left([cellref], 3) so that your If...then...Else is only trying to match the three digits.  Of course, you could also use an If...then...Else construction in the data source it self to populate a field with the fraternity - university name.

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2016-10-03T01:17:42+00:00

    Is there a limit to how many of these conditions you can have?

    I want to insert text into a directory listing based on a code in the data source.

    So I would have something like

    { IF {MERGEFIELD Member_} = "503*"  {INCLUDETEXT "Epsilon - Syracuse University"}

    { IF {MERGEFIELD Member_} = "562*"  {INCLUDETEXT "Beta Tau - University of Florida"}

    { IF {MERGEFIELD Member_} = "571*"  {INCLUDETEXT "Gamma Zeta - Northern Illinois University"}

    And so on.

    I tried to format if like this and am getting unpredictable results:

    { IF {MERGEFIELD Member_} = "503*"  "Epsilon - Syracuse University" ""}

    { IF {MERGEFIELD Member_} = "562*"   "Beta Tau - University of Florida" ""}

    { IF {MERGEFIELD Member_} = "571*"   "Gamma Zeta - Northern Illinois University" ""}

    Thanks for the help!

    Was this answer helpful?

    0 comments No comments