Inhibiting empty lines in generated documents

When generating Word and PDF documents, there are sometimes situations where the generated content produces an empty line because the corresponding merge field contains no data. A common example is the address block in a letter, in which you might include the name, company name and street address of a contact. The address is set up so that the company name appears on a line by itself, as in the screen shot below. Notice that we use “soft returns” at the end of each line in the address block, by typing Shft-Enter instead of Enter. This ensures that the lines of the address block are kept together in one paragraph.

Below are the results obtained when all the fields are available (at left), and when the company name is not available (at right):

 

Notice that if the contact’s company name is not available, an unsighly blank line appears between the contact name and the street, as in the screen shot above right.

To remove the unnecessary blank line, we use the IF-THEN conditional directives that the merge tool offers. (You can read more about these directives.) The basic idea is to embed the company name within an IF-THEN condition, but ensure that the soft return before the company name appears within the IF-THEN. In other words, the IF part appears on the first line, but the ENDIF appears on the second line. This ensures that, when the IF condition fails because there is no company name, the line break induced by the soft return also disappears. See screen shot below. You can download this template if you like.

Below are the results obtained when all the fields are available (at left), and when the company name is not available (at right);

 

Powered by BetterDocs