Microsoft KB Archive/90393

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

Article ID: 90393

Article Last Modified on 1/18/2007

-

APPLIES TO


 * Microsoft Word 97 Standard Edition

-



This article was previously published under Q90393



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 IF field. If you do not include the FalseResult argument, Word returns nothing if the result is false.

Conditional Mail 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}= &quot;Seattle&quot;

&quot;Tuesday, March 21.&quot; &quot;{if {city}= &quot;Los Angeles&quot; &quot;Wednesday, March

22.&quot; {if {city}= &quot;San Francisco&quot; &quot;Thursday, March 23.&quot; &quot;Friday,

March 24.&quot;}&quot;}&quot;}.

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 mail 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 &quot;TrueResult&quot; &quot;{IF test2 &quot;TrueResult&quot; &quot;FalseResult&quot;}&quot;}


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

{IF test1 &quot;{IF test2 &quot;TrueResult&quot; &quot;FalseResult&quot;}&quot; &quot;FalseResult&quot;}

Constructing a Boolean AND Statement
This AND statement

IF (field <> &quot;A&quot;) AND (field <> &quot;B&quot;) THEN

&quot;TrueResult&quot;

ELSE

&quot;FalseResult&quot;

END IF

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

{IF field <> &quot;A&quot; &quot;{IF field <> &quot;B&quot; &quot;TrueResult&quot; &quot;FalseResult&quot;}&quot; &quot;FalseResult&quot;}

Constructing a Boolean OR Statement
This OR statement

IF (field = &quot;A&quot;) OR (field = &quot;B&quot;) THEN

&quot;TrueResult&quot;

ELSE

&quot;FalseResult&quot;

END IF

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

{IF field = &quot;A&quot; &quot;result&quot; &quot;{IF field = &quot;B&quot; &quot;TrueResult&quot; &quot;FalseResult&quot;}&quot;}

Additional query words: winword winword2 mailmerge mail merge how to 8.0 word97 print printmerge

Keywords: kbfaq kbfield kbinfo kbmerge kbualink97 kbusage KB90393

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.