WD: How to Use Nested IF Fields in a Print Merge Document

Last reviewed: March 4, 1998
Article ID: Q90393
The information in this article applies to:
  • Microsoft Word for Windows, versions 1.0, 1.1, 1.1a, 2.0, 2.0a, 2.0a-CD, 2.0b, 2.0c, 6.0, 6.0a, 6.0c
  • Microsoft Word for Windows 95, versions 7.0, 7.0a
  • Microsoft Word for Windows NT, version 6.0
  • Microsoft Word 97 for Windows

SUMMARY

In Word for Windows, you can use the IF field to obtain customized print merge results. By nesting IF fields, as described in this article, you can obtain conditional print merge results and logically construct the equivalent of Boolean AND and OR statements.

MORE INFORMATION

The IF field syntax is as follows

   {IF Exp Op Exp TrueResult [FalseResult]}

where TrueResult and FalseResult can be either text or a nested IF field. If you do not include the FalseResult argument, Word returns nothing if the result is false.

Conditional Print Merge Results Using IF Field

In the following example, each form letter requests that its recipient attend a meeting on a different date, based on the city field.

Data Document:

   NAME, ADDRESS, CITY, STATE, ZIP
   Bill Brown, 123 Acorn St., Seattle, WA, 98035
   Sandy Sill, 234 Ash St., Los Angeles, CA, 99888
   Fred Turner, 345 Birch Ave., San Francisco, CA, 45555
   Lynne Lowe, 456 Walnut St., Boise, ID, 83240

Main Document:

   Please attend the Windows meeting on {if {city}= "Seattle"
   "Tuesday, March 21." "{if {city}= "Los Angeles" "Wednesday, March
   22." {if {city}= "San Francisco" "Thursday, March 23." "Friday,
   March 24."}"}"}.

Merged Results:

   (for Mr. Brown)
   Please attend the Windows meeting on Tuesday, March 21.

   (for Ms. Sill)
   Please attend the Windows meeting on Wednesday, March 22.

   (for Mr. Turner)
   Please attend the Windows meeting on Thursday, March 23.

   (for Ms. Lowe)
   Please attend the Windows meeting on Friday, March 24.


Using IF Field to Perform Boolean AND and OR Operations

The IF field does not directly support Boolean AND and OR operations in a print merge. However, the logical AND and OR operators are actually just abbreviations of nested IF statements; therefore, you can construct the equivalent of Boolean AND and OR operations using the following syntax:

  • OR: Position the second test inside the second set of quotation marks.

    {IF test1 "TrueResult" "{IF test2 "TrueResult" "FalseResult"}"}

  • AND: Position the second test inside the first set of quotation marks.

    {IF test1 "{IF test2 "TrueResult" "FalseResult"}" "FalseResult"}

Constructing a Boolean AND Statement

This AND statement

   IF (field <> "A") AND (field <> "B") THEN
      "TrueResult"
   ELSE
      "FalseResult"
   END IF

can be translated to an IF statement for use in a print merge as follows:

   {IF field <> "A" "{IF field <> "B" "TrueResult" "FalseResult"}"
    "FalseResult"}

Constructing a Boolean OR Statement

This OR statement

   IF (field = "A") OR (field = "B") THEN
      "TrueResult"
   ELSE
      "FalseResult"
   END IF

can be translated to an IF statement for use in a print merge as follows:

   {IF field = "A" "result" "{IF field = "B" "TrueResult"
   "FalseResult"}"}

REFERENCES

"Microsoft Word for Windows User's Guide," version 2.0, pages 639-644

"Word for Windows Companion," version 2.0, Mark Crane and M. David Stone and Alfred Poor, Microsoft Press, 1992, pages 584-85

"Word for Windows Companion," version 1.x, Mark W. Crane, The Cobb Group, 1990, pages 608-609

"Microsoft Word for Windows and OS/2 Technical Reference," pages 41- 42, 66-67, 357


KBCategory: kbusage kbhowto
KBSubcategory: kbfield kbmerge

Additional query words: 2.0 2.0a 2.0a-CD 2.0b 2.0c 1.0 1.10
1.10a
word7 word6 7.0 word95 6.0 6.0a 6.0c winword winword2 mailmerge
mail merge how to 8.0 word8 word97
Keywords : kbfield kbhowto kbmerge kbualink97 kbusage kbfaq
Version : 1.x 2.x 6.0 6.0a 6.0c 7.0 7.
Platform : WINDOWS


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: March 4, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.