Microsoft KB Archive/179674

= WD98: How to Suppress Blank Spaces in a Mail Merge =

Article ID: 179674

Article Last Modified on 10/4/2002

-

APPLIES TO


 * Microsoft Word 98 for Macintosh

-



This article was previously published under Q179674



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.



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 <>. 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 represents pressing the space bar once, while  represents pressing the RETURN key once.

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

<> <> <>

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

{MERGEFIELD Title} {MERGEFIELD FirstName}

{MERGEFIELD LastName}

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

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} "}

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} ") otherwise do nothing."

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

 Display the field codes by pressing OPTION+F9. Position the insertion point before the Title merge field. Press COMMAND+F9 to create a new field (field1). With the insertion point inside field1, type

If

where space is the character you get when you press the SPACEBAR.</li> 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 Title

</li> Move the insertion point outside of field2 (one place to the right) and while the insertion point is still inside field1, type

<> "" "

</li> Create another new field (field3) inside field1 by pressing COMMAND+F9.</li> With the insertion point in field3, type:

MERGEFIELD Title

</li> Move the insertion point outside of field3 (one place to the right) and while still inside field1 type:

"

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

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

{MERGEFIELD FirstName} {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.</li> Delete the original Title merge field and the space behind it, and Toggle the field codes off by pressing Option+F9.</li></ol>

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.

<div class="references_section">