WD: Using Comparison IF Statements with Text and Numbers (176769)



The information in this article applies to:

  • Microsoft Word for the Macintosh 6.0
  • Microsoft Word for the Macintosh 6.0.1
  • Microsoft Word for the Macintosh 6.0.1a
  • Microsoft Word 98 Macintosh Edition

This article was previously published under Q176769

SYMPTOMS

When you use the mail merge IF function for comparisons, the returned data may be different from what you expect.

CAUSE

This problem will occur if a field in the data source contains text in some records and numbers in other records.

WORKAROUND

When the comparison is set up to select a number greater or less than another value, such as {If {MERGEFIELD number} > 70 "True condition statement" "False condition statement"}, fields that contain text will also be printed. This is because Word considers all text to have a greater "value" than numbers.

To instruct Word to return only numeric values, use a nested IF statement. One that restricts text and one that returns the correct numeric value. For example:
   {If {MERGEFIELD number} > 70 "{If {MERGEFIELD NUMBER} < "A"
   "{MERGEFIELD number" " "} " "}
				

Word 6.x for the Macintosh

  {If {MERGEFIELD number} > 70 "{If {MERGEFIELD NUMBER} < "A"
  "{MERGEFIELD number" " "} " "}
				
The nested IF Statement requests text less than "A" and therefore returns no text in the field with text entries, and it then requests numbers greater than 70 for those records with numeric values over 70.

Word 98 Macintosh Edition

  {If {MERGEFIELD number} > 70 "{If {MERGEFIELD NUMBER} < "a"
  "{MERGEFIELD number" " "} " "}
				
The nested IF Statement requests text less than "a" and therefore returns no text in the field with text entries, and it then requests numbers greater than 70 for those records with numeric values over 70.

MORE INFORMATION

For information about this situation in earlier versions of Word, please see the following article in the Microsoft Knowledge Base:

75950 WD: Using Comparison IF Statements with Text and Numbers


Modification Type:MajorLast Reviewed:10/4/2002
Keywords:kbfield kbmerge kbprb KB176769