Share via

How to supress blank lines in word with mergefield if empty

Anonymous
2023-07-13T04:12:28+00:00

I've searched and searched but have not come up with anything that works.

Here's the scenario.

I use a program called ServiceM8 which has a "Forms" section. I have a "form" which asks a bunch of questions, which can be simple yes/no answers or text fields and can add photos and then it generates a PDF report from a word template.

The word template I have has a bunch of mergefields. - { MERGEFIELD  image_form_photos_of_areas_not_inspected_medium  \* MERGEFORMAT } which will show a photo that has been selected and will show in the pdf report.

However, if there is no photo selected in the form, the report will generate a blank line for the document.

Sometimes I have 10 of these mergefields for photos (2 per line so photos show side by side) and the mergefields are above the other in the report) and the report it produces has 5 blank lines so the report has huge gaps between the text.

Is there a way to format the mergefields so if they are "false" and don't have a photo attached then the word document doesn't show a blank line?

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

7 answers

Sort by: Most helpful
  1. Anonymous
    2023-12-01T17:24:51+00:00

    How come every reply to Microsoft Answers makes me feel like I am having a stroke.

    50+ people found this answer helpful.
    0 comments No comments
  2. Doug Robbins - MVP - Office Apps and Services 322.9K Reputation points MVP Volunteer Moderator
    2024-02-29T01:16:11+00:00

    I am not sure why you 3 sets of records -15, -16, -17 as it would be more normal just to have

                                                                 «AddresseeSalutation\_Donor\_Addressee»
    

    «Address_Donor_Address_line_1»

    «Address_Donor_Address_line_2»

    «Address_Donor_City», «Address_Donor_State»  «Address_Donor_ZIP_Code»

    and, if you want to suppress the address fields if they are blank, use

    «AddresseeSalutation_Donor_Addressee»{ IF { MERGEFIELD Address_Donor_Address_line_1 } <> "" "¶

    «Address_Donor_Address_line_1»
    «Address_Donor_Address_line_2»
    «Address_Donor_City», «Address_Donor_State»  «Address_Donor_ZIP_Code»" }

    You must use CTR:+F9 to insert each pair of field delimiters { } and press the Enter key where the ¶ appears at the end of the first line.

    4 people found this answer helpful.
    0 comments No comments
  3. Doug Robbins - MVP - Office Apps and Services 322.9K Reputation points MVP Volunteer Moderator
    2024-07-07T11:26:28+00:00

    That may be an application for the Many to One facility on my Merge Tools Add-in that is contained in the MERGE TOOLS ADD-IN.zip file that you can download from:

    https://mergetoolsaddin.com/

    Extract the files from the archive and read the:

    “READ ME – Setting up and using the Merge Tools Add-in.pdf

    to see how to install and use the various tools.

    Using those tools, it is possible to perform the following types of merge that cannot be done with Mail Merge “out-of-the-box”:

    • Merge to e-mail messages either with or without attachments, with the documents created by the merge being sent as either Word or PDF attachments or as the body of the e-mail message .  The email messages can, if necessary, also be sent to CC and BCC addresses and the subject of the message can include data from a field in the data source.
    • Merge to individual documents in either Word or PDF format with the filenames being supplied by the data in one of the fields in the data source
    • Many to One type merges, which can be used for creating documents such as invoices where there are multiple records in the data source that have common data in one of the fields
    • Merging to a document that will include a chart that is unique to each record in the data source
    • Merging a document with Content Controls
    • Merging a document that contains Legacy FormFields
    • Duplex Merges
    • Merging to a printer that will collate and staple the output created from each record in the data source.

    The requirements for using the system are:

    • The mail merge main document must be of the Letters type, though that does not mean that the output cannot be sent as an e-mail message where relevant.
    • For the Many To One, Merge with Attachments and Merge to Individual Docs utilities, the data source may be either a table or query in an Access database, or in the form of an Excel worksheet. For the Chart Merge utility, see the Mail Merging with Charts document that is included in the Merge Tools Add-in Zip file for additional requirements for the data source for use with that utility
    • For a data source in the form of an Excel worksheet, the field names must be in the first row of the worksheet and there must be a field name in all of the cells in that row that are within the range of columns that contain the data.
    • For both types of data source, the field names must contain only alphanumeric characters (No @,#,$,%,&,(,), etc) and the field names must not start with a numeric character (0-9). The number of characters in the field names, including spaces, must not be more than 40.

    The MergeTools Add-in will NOT work with the “New Outlook”, which is just a re-badged version of Windows Mail and like its predecessor, it does not support automation and hence will not send the messages created by the MergeTools Add-in.

    Be aware, that any messages that you had tried to send with the “New Outlook” will have been placed in the Outbox of the original Outlook and they will be sent as soon as you revert to that version of Outlook.   If you do not want that to happen, you should put Outlook Off-line, or disconnect your computer from the Internet.

    2 people found this answer helpful.
    0 comments No comments
  4. Anonymous
    2024-07-04T19:32:58+00:00

    Is it possible to add or eliminate rows of a table using this or something similar? If I have a table for various elements but not all records I'm importing have the same number of those elements, can the table expand/contract to accommodate? The elements are set up as columns in the source file and can range from 1 to 5 combinations. I'd rather not have a 5 row table on my merge document as that takes up a lot of space and leaves it looking as though something is missing

    Desc. Attribute 1 Attribute 2 Attribute 3
    desc 1 data data data
    empty empty empty empty
    1 person found this answer helpful.
    0 comments No comments
  5. Anonymous
    2023-07-13T06:03:55+00:00

    Hello

    I’m Adeyemi and I’d be happy to help you with your question. In this forum, we are Microsoft consumers just like yourself.

    Yes, there is a way to suppress blank lines in Word when using merge fields.

    One way to do this is by toggling the field codes in the mail merge document so that merge fields are presented in the following manner: {MERGEFIELD *Field_name*}.

    You can accomplish this by pressing Alt+F9. Then, remove any carriage returns and spaces between the merge field that you want to be suppressed if it is blank and the previous merge field. Finally, insert the following text within the merge field at the closing bracket: \\b " ".

    Another way to suppress blank lines when a merge field is empty is by using an IF field. For example, if you have an Address1, Address2, City, State, and Zip fields and there may be no data in the Address2 field, you can use the following field construction: { MERGEFIELD Address1 } { IF { MERGEFIELD Address2 } <> \"\" \" { MERGEFIELD Address2 }¶ { MERGEFIELD City } { MERGEFIELD State } { MERGEFIELD Zip }\" \" { MERGEFIELD City } { MERGEFIELD State } { MERGEFIELD Zip }\" }. You must use CTRL+F9 to insert each pair of field delimiters and you use Alt+F9 to toggle off their display. Where the appears above, press Enter or Shift+Enter.

    I hope this helps! 😊

    You can check these similar conversations too: https://answers.microsoft.com/en-us/msoffice/forum/all/eliminating-blank-lines-in-mail-merge-if-fieldis/eeecb934-e23d-4dfb-9e98-f23e13436a32. https://answers.microsoft.com/en-us/msoffice/forum/all/mail-merge-how-to-suppress-blank-lines/2039a43b-9c84-4423-abf2-3213043ae4b3.

    1 person found this answer helpful.
    0 comments No comments