Tip of the Week #141 – Empty Merge Fields in Word Documents
Senior Consultant Lutz Schmieder brings us this week’s helpful tip.
If, in “the old days” a merge field was empty, Word would simply clear the paragraph out of the document. Now with the new merge functionality, it will delete an empty line.
You can see there are blank lines between “Finishing” and “Quantity / Price”. This is because the template has Merge Fields between those lines. Since these fields are basically placeholders in the template, they are not filled in if there’s no data, but after the field there’s an actual Linefeed (Paragraph marker).
In order to delete the whole paragraph when there is no data, you need to modify the template slightly so the server-side merge recognizes the request for deletion.
Steps to do this:
- Export/Open the template from the Document Setup
- Select the field you want to mark as ‘Delete paragraph when empty’, then Right-click the field and select “Edit Field.”
- Add #dp (for Delete Paragraph) to the fieldname so it looks like this:
- Click OK
- Repeat for each field that can be deleted if empty
- Close the template and choose Yes on the “Import” confirmation dialog
There is also an option for Table Row:
#dr : Delete Row
Therefore, if you want to delete a complete table line (row) if the merge field doesn’t have a value, use the #dr parameter instead of the #dp.
Thank you Lutz!