Insert Conditional Paragraph in Word Merge Template

Posted on 2011-02-17
Last Modified: 2012-05-11
Is there a way to insert a blank paragraph (or in otherwords a carriage return) in a word merge temlate that is based on one of the merge fields in the document's data source meating a certain condition?  For example, I have a letter template that contains a table near the bottom representing a CC block.  The block may contain 1, 2, or many names, each separated by a carriage return.  If the count of the names exceeds 7 then the remaining names print on the next page.  What I want instead is for the tempate to remove the paragraphs immediately above the CC table so all the names move up and the letter can still exist on one page.

Thanks in advance for your response.
Question by:SueJStevens
1 Comment
LVL 50

Accepted Solution

Ingeborg Hawighorst earned 500 total points
ID: 34920345

this would be easiest if your source data contained a field with a count of the names, for example ccCount. Then you can use the {IF} field in your merge like

{ IF {MERGEFIELD ccCount} > 7 "<insert page break here>{MERGEFIELD ccName1} ¶
{MERGEFIELD ccName2} ¶
{MERGEFIELD ccName3} ¶
{MERGEFIELD ccName4} ¶
{MERGEFIELD ccName5} ¶
{MERGEFIELD ccName6} ¶
{MERGEFIELD ccName7} ¶
{MERGEFIELD ccName8} ¶
{MERGEFIELD ccName9}" "{MERGEFIELD ccName1} ¶
{MERGEFIELD ccName2} ¶
{MERGEFIELD ccName3} ¶
{MERGEFIELD ccName4} ¶
{MERGEFIELD ccName5} ¶
{MERGEFIELD ccName6} ¶
{MERGEFIELD ccName7} ¶
{MERGEFIELD ccName8} ¶
{MERGEFIELD ccName9}" }

The EE comment is not the best way to write field codes. Please do not write the {} manually, but use Ctrl-F9 to insert a field, then write between the brackets. The {IF} syntax is

{ IF condition "do when true" "do when false" }

You can have fields within the "do when true" and "do when false" and you need to enclose the whole "do when true/false" with double quotes. Within the "do when true/false" you can have paragraph marks, page breaks, etc.

I'll be happy to arrange the fields in your document, if you send me the merge document with the field names in place. You can replace the text with dummy text. I really only need the part with the CC block.

cheers, teylyn

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When creating Microsoft Word-based forms there may be a need to have a form field repeated throughout the whole document. For instance, with a company name, you may want this information repeated automatically throughout the document rather than man…
This is written from a 'VBA for MS Word' perspective, but I am sure it applies to most other MS Office components where VBA is used.  One thing that really bugs me is slow code, ESPECIALLY when it's mine!  In programming there are so many ways to…
This video walks the viewer through the process of creating an MLA formatted document, as well as a bibliography with citations.
This video walks the viewer through the process of creating Hyperlinks for the web and other documents. Select the "Insert" tab: Click "Hyperlink":  Type "http://" followed by a web address to reference a website or navigate to a document to ref…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question