When you use the WordTemplate object to populate a WordWriter template document with data retrieved from a data source, you may have situations in which a merge field is not bound to a value. The most common scenario is creating a mailing address. Each field of a mailing address may be represented by a merge field. Typically, the second line of the address is optional. In the generated document, if the merge field corresponding to the second line of the address does not have a value, a blank line may be present.
In Microsoft Word, a blank line generated during a mail merge can be suppressed using application settings. With WordWriter, a blank line is not automatically removed.
The issue is illustrated in the following images:
| WordWriter template document: |
Generated document: |
|
|
|
The following discussion uses a merge field called Address_Line_2 as an example, but is applicable to any field with optional value.
In the WordWriter template document, if the line break is separate from the Address_Line_2 merge field, the line break will be present in the generated document whether or not there is a value for Address_Line_2.
In order to prevent a line break if Address_Line_2 is not present, do not put a line break after the Address_Line_2 merge field in the WordWriter template document. Instead, insert the line break only when the Address_Line_2 is present. To do so, perform the following steps in Microsoft Word:
-
In the WordWriter template document, insert a line break within the Address_Line_2 data marker itself:
- Right-click on the Address_Line_2 merge field
- Select Toggle Field Codes
- After the merge field name, enter \f, then press Enter to get a new line.
-
You should see the following:
{ MERGEFIELD Address_Line_2 \f
\* MERGEFORMAT }
- If you select "View Paragraph marks" (Tools, Options, View, Paragraph marks), you should see a paragraph mark (¶) in the field code as follows:
-
As a final check, if you right-click on the Address_Line_2 merge field, then select Edit field, the "Text to be inserted after" option should be checked.
After you follow the above steps, the address in the generated document should no longer contain a blank line, as shown in the below image:
|