You are currently offline, waiting for your internet to reconnect

WD97: How to Use Nested IF Fields in a Mail Merge Document

This article was previously published under Q90393
Retired KB Content Disclaimer
This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.
SUMMARY
In Word, you can use the IF field to obtain customized mail merge results. By nesting IF fields, as described in this article, you can obtain conditional mail 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 IFfield. If you do not include the FalseResult argument, Word returnsnothing if the result is false.

Conditional Mail Merge Results Using IF Field

In the following example, each form letter requests that its recipientattend 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 operationsin a mail merge. However, the logical AND and OR operators areactually just abbreviations of nested IF statements; therefore, you canconstruct the equivalent of Boolean AND and OR operations using thefollowing syntax:

  • OR: Position the second test inside the second set of quotationmarks.

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

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

    {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 mail merge asfollows:
{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 mail merge asfollows:
{IF field = "A" "result" "{IF field = "B" "TrueResult""FalseResult"}"}
winword winword2 mailmerge mail merge how to 8.0 word97 print printmerge
Properties

Article ID: 90393 - Last Review: 01/18/2007 19:10:00 - Revision: 1.1

  • Microsoft Word 97 Standard Edition
  • kbfaq kbfield kbinfo kbmerge kbualink97 kbusage KB90393
Feedback