Share via

Creating Paragraph Breaks within Conditional Field Codes

Anonymous
2014-11-09T02:04:22+00:00

I'm trying to create a sequential list using field codes and mail merge. My problem is that certain items do not need to appear on the list, depending on how the mail merge goes. This is confusing, so I will give an example.

Let's say I'm putting together a list of quantities for various fruits. I've got a mail merge document that tells me how many apples, oranges, and pears I have. So the list might look like:

  1. There are 32 apples.
  2. There are 27 oranges.
  3. There are 3 pears.

Using field codes it looks more like:

(SEQ list1) There are (MERGEFIELD "Apples") apples.

(SEQ list1) There are (MERGEFIELD "Oranges") oranges.

(SEQ list 1) There are (MERGEFIELD "Pears") pears.

Now, if there are no oranges, I don't want it to be on the list at all. I just want the list to look this this:

  1. There are 32 apples.
  2. There are 3 pears.

To do this, I use if/then conditioning. (IF (MERGEFIELD Oranges) = 0 "" "(SEQ list1) There are (MERGEFIELD "Apples") apples. This is successful in removing the oranges from the list, but there remains a space:

  1. There are 32 apples.
  2. There are 3 pears.

I've tried every which way I can thing to get rid of that space, but I can't figure it out. Perhaps someone here could help me.

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

Suzanne S Barnhill 278.1K Reputation points MVP Volunteer Moderator
2014-11-09T03:13:56+00:00

What you need is something more like this:

{ IF { MERGEFIELD "Apples" } > 0 "{ SEQ list1}. There are { MERGEFIELD "Apples" } apples.

" }{ IF { MERGEFIELD "Oranges" } > 0 "{ SEQ list1}. There are { MERGEFIELD "Oranges" } oranges.

" }{ IF { MERGEFIELD "Pears" } > 0 "{ SEQ list1}. There are { MERGEFIELD "Pears" } pears.

" }

That is, the paragraph break must be inside the TrueText so that it (along with the rest of the numbered item) does not appear if the condition is not met.

Was this answer helpful?

0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Anonymous
    2014-11-09T16:24:46+00:00

    Suzanne:

    Thank you, that worked! It's odd, because when I put a paragraph break at the beginning, it didn't work, whereas when there's one at the end it does. Solved the problem though, thank you!

    Was this answer helpful?

    0 comments No comments
  2. Paul Edstein 82,861 Reputation points Volunteer Moderator
    2014-11-09T07:21:46+00:00

    Unfortunately, you can't conditionally insert SEQ-numbered paragraphs and be ensure of a valid numbering sequence. What you'll get if there are no oranges, for example, is:

    1. There are 32 apples.
    2. There are 3 pears.

    and the SEQ field will no longer be present.

    You could, however, use a set of fields coded like:

    {SET Val 0}{IF{MERGEFIELD Apples}> 0 "{SET Val {=Val+1}}{Val # 0} There are {MERGEFIELD Apples} apples¶

    "}{IF{MERGEFIELD Oranges}> 0 "{SET Val {=Val+1}}{Val # 0} There are {MERGEFIELD Oranges} oranges¶

    "}{IF{MERGEFIELD Pears}> 0 "{SET Val {=Val+1}}{Val # 0} There are {MERGEFIELD Pears} pears¶

    "}

    or, with more sophistication:

    {SET Val 0}{IF{MERGEFIELD Apples}> 0 "{SET Val {=Val+1}}{Val # 0} There {={MERGEFIELD Apples}-1 # "'are';;'is'"} {MERGEFIELD Apples} apple{={MERGEFIELD Apples}-1 # "'s';;"}¶

    "}{IF{MERGEFIELD Oranges}> 0 "{SET Val {=Val+1}}{Val # 0} There {={MERGEFIELD Oranges}-1 # "'are';;'is'"} {MERGEFIELD Oranges} orange{={MERGEFIELD Oranges}-1 # "'s';;"}¶

    "}{IF{MERGEFIELD Pears}> 0 "{SET Val {=Val+1}}{Val # 0} There {={MERGEFIELD Pears}-1 # "'are';;'is'"} {MERGEFIELD Pears} pear{={MERGEFIELD Pears}-1 # "'s';;"}¶

    "}

    In the above constructions, it's the {Val # 0} field that outputs the sequential numbers. The {SET Val 0} field at the start resets the numbering for each merge record and the {SET Val {=Val+1}} increments it only if the field has a value > 0.

    Note: The field brace pairs (i.e. '{ }') for the above examples are created in the document itself, via Ctrl-F9 (Cmd-F9 on a Mac); you can't simply type them or copy & paste them from this message. Nor is it practicable to add them via any of the standard Word dialogues. The spaces represented in the field constructions are all required. Instead of the ¶, you should use real line/paragraph breaks.

    Was this answer helpful?

    0 comments No comments