WD98: How to Suppress Blank Spaces in a Mail Merge

Last reviewed: February 3, 1998
Article ID: Q179674
The information in this article applies to:
  • Microsoft Word 98 Macintosh Edition

SUMMARY

During a mail merge, you may want to eliminate blank spaces when there is no information available for a merge field in a line of text. This articles discuses why blank spaces occur, and it includes a method you can use to eliminate these blank spaces.

MORE INFORMATION

Why Do Blank Spaces Occur?

Blank spaces occur most often in a mail merge when you use a title, honorific, or middle initial with a name. When these merge fields are used, a space is required between them and the name they refer to. If there is no data for that field, the extra space needs to be eliminated.

Using an IF Field to Remove an Unwanted Space Character

You can use an IF (conditional) field and make the space part of the conditional field so that when the field in question is empty, the space is not created.

NOTE: In general, when you view a mail merge main document, merge field names appear in chevrons <<MERGE FIELD>>. To view the actual field codes that are in the document, press and hold the OPTION key and then press the F9 key to toggle the field codes off and on. Note also that the {} (curly brackets) that define a field cannot be simply typed. To create a pair of special brackets (create a field) press and hold the COMMAND key and then press F9.

In the samples that follow <space> represents pressing the space bar once, while <Return> represents pressing the RETURN key once.

In a main merge document a typical name line often resembles the following:

   <<Title>><space><<FirstName>><space><<LastName>><Return>

To see the actual field codes press, OPTION+F9. The resulting text will resemble the following:

   {MERGEFIELD Title}<space>{MERGEFIELD FirstName}<space>
   {MERGEFIELD LastName}<Return>

NOTE: Ignore the line wrapping on the screen for these examples. The line in the merge will actually end at the <Return>.

The space after the Title merge field can be eliminated by placing the merge field and the space in an IF conditional field. The resulting field will look like this:

   {IF {MERGEFIELD Title}<>"" "{MERGEFIELD Title}<space>"}

The logic of the IF field reads "If the Title field ({MERGEFIELD Title}) is greater than or less than (<>) empty ("") (this is a programming way of saying not empty) insert what is in the Title field plus a space ("{MERGEFIELD Title}<space>") otherwise do nothing."

To create the IF field for this example, follow these steps:

  1. Display the field codes by pressing OPTION+F9.

  2. Position the insertion point before the Title merge field.

  3. Press COMMAND+F9 to create a new field (field1). With the insertion point inside field1, type

          If<space>
    

    where space is the character you get when you press the SPACEBAR.

  4. Without moving the insertion point, create another new field inside field1 by pressing COMMAND+F9 creating (field2). With the insertion point in field2 type:

          MERGEFIELD<space>Title
    

  5. Move the insertion point outside of field2 (one place to the right) and while the insertion point is still inside field1, type

          <><space>""<space>"
    

  6. Create another new field (field3) inside field1 by pressing COMMAND+F9.

  7. With the insertion point in field3, type:

          MERGEFIELD Title
    

  8. Move the insertion point outside of field3 (one place to the right) and while still inside field1 type:

          <space>"
    

    The conditional IF field is now complete. The name line should now resemble the following:

          {IF {MERGEFIELD Title}<>"" "{MERGEFIELD Title}<space>"}
          {MERGEFIELD FirstName}<space>{MERGEFIELD LastName}<Return>
    
    NOTE: Ignore the line wrapping displayed here. There should be no line break between the end of the IF field and the start of the FirstName merge field. This method will work with any merge field by simply changing the name of the merge fields inside the IF field to correspond with the appropriate merge field names in your data document.

  9. Delete the original Title merge field and the space behind it, and Toggle the field codes off by pressing Option+F9.

NOTE: The IF field does not appear inside chevrons in this view as the merge fields do. What will be seen at that location in the main document is the result of the IF field for the current record. If that merge field is empty in the current record there will be nothing in that location, if the merge field contains text that text will be displayed at the If field location.

REFERENCES

For information about this subject in other versions of Word, please see the following articles in the Microsoft Knowledge Base:

   ARTICLE-ID: Q72441
   TITLE     :WD: Suppressing Blank Spaces in a Print Merge (Mail Merge)
Keywords          : kbmerge
Version           : MACINTOSH:98
Platform          : MACINTOSH
Issue type        : kbhowto kbinfo


================================================================================


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: February 3, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.