How to Suppress Blank Fields in a Text Merge

ID: Q121411

The information in this article applies to:

SUMMARY

You can suppress blank fields in a FoxPro text merge by programmatically creating the TEXTMERGE command and then using macro substitution to execute the command, as shown in the example below.

MORE INFORMATION

This example assumes that you have a table with three fields

   NAME
   ADDRESS1
   ADDRESS2

and that you want to perform a text merge that produces output in the following format:

   <Name>
   <Address1>
   <Address2>
   <Date>

   <Body of letter>

If the ADDRESS2 field is empty, you want the date to appear directly underneath ADDRESS1, with no blank line where ADDRESS2 would normally appear.

The following program illustrates how to create the desired output.

   USE <table>
   SET TEXTMERGE TO outfile.txt
   SET TEXTMERGE ON
   SCAN
      * Test the ADDRESS2 field and return the appropriate text merge
      * character.
      cmnd=IIF(EMPTY(address2),"\\","\<<address2>>")
      \<<name>>
      \<<address1>>
      * Use macro substitution to execute the command.
      &cmnd
      \<<DATE()>>
      \
      \body of letter goes here
      * Print two empty lines between records.
      \
      \
   ENDSCAN
   SET TEXTMERGE OFF
   SET TEXTMERGE TO

REFERENCES

FoxPro "Language Reference," SET TEXTMERGE command

Additional reference words: FoxMac FoxDos FoxWin 2.00 2.50 2.50a 2.50b 2.50c 2.60 2.60a print merge printmerge textmerge suppressing empty extra extraneous KBCategory: kbprg kbcode KBSubcategory: FxprgMacrosub

Last Reviewed: August 28, 1995