WD: Conditional Alphanumeric Merge May Yield Incorrect Results

ID: Q189027


The information in this article applies to:
  • Microsoft Word for Windows, versions 2.0, 2.0a, 2.0a-CD, 2.0b, 2.0c, 6.0, 6.0a, 6.0c
  • Microsoft Word for the Macintosh, versions 6.0, 6.0.1, 6.0.1a
  • Microsoft Word for Windows 95, versions 7.0, 7.0a


SYMPTOMS

A print merge or mail merge operation may yield incorrect results if you use a conditional statement to evaluate alphanumeric data when the first character of the data is numeric.


CAUSE

This behavior is by design of Microsoft Word. This happens because conditional statements (IF fields) evaluate only the first two characters of a numeric string.


WORKAROUND

To work around this problem, use the appropriate method for your version of Word.

Word Versions 6.x, 7.x

Modify the data so that each field begins with a non-numeric character. Then, modify the conditional field in the main merge document to match the data. To do this, follow these steps:
  1. In the data document, add a character to the beginning of each data field that starts with a number. You can use any character, such as a parenthesis (you can also add one to the end of the field, so that it's easier to read) or an ampersand (&). This makes the first character in the number field a character instead of a numeral.

    Modified with parentheses:
    
          ---------------------------------
          |  Rec_Num  |Name      |Number  |
          ---------------------------------
          |     1     |John      |(1AA)   |
          ---------------------------------
          |     2     |Bill      |(1AB)   |
          ---------------------------------
          |     3     |Fred      |(2AA)   |
          ---------------------------------
          |     4     |George    |(ABC)   |
          --------------------------------- 
    Modified with an ampersand:
    
          ---------------------------------
          |  Rec_Num  |Name      |Number  |
          ---------------------------------
          |     1     |John      |&1AA    |
          ---------------------------------
          |     2     |Bill      |&1AB    |
          ---------------------------------
          |     3     |Fred      |&2AA    |
          ---------------------------------
          |     4     |George    |&ABC    |
          --------------------------------- 


  2. In the main document, edit the test portion of the conditional field so that it matches the newly modified data. For example:

    If the data is surrounded by parentheses, modify the field to look like this:
    {IF {MERGEFIELD number} = "(1A)" "This is true"}
    If the data begins with an ampersand, modify the field to look like this:
    {IF {MERGEFIELD number} = "&1A" "This is true"}


Word Version 2.x

If your alphanumeric data contains entries that begin with a numeric character, use the print merge Record Selection feature to perform a conditional merge of the data. By setting record selection rules, you can merge only data records that meet the criteria you specify.

The disadvantage of this workaround is that you must perform multiple print merge operations if your main document contains more than one conditional statement for alphanumeric fields. In this case, you must modify your main document for each condition, change the Record Selection settings to evaluate each condition individually and then perform a separate print merge operation. The functionality of the Record Selection feature differs from that of an IF field, so you must modify your print merge procedure accordingly.

For example, the following procedure uses the Record Selection feature to perform a conditional print merge of the sample data file above. This procedure replaces the following conditional statement:
{IF {MERGEFIELD TEST} = "1AB" "This is true"}
To use this procedure, follow these steps:
  1. Attach the data file to the main document and then activate the main document.


  2. On the File menu, click Print Merge, and then click Merge.


  3. Click Record Selection.


  4. In the Field Name list, click to select Test.


  5. In the Is list, click to select Equal To.


  6. In the Compared To box, type 1AB and then click Add Rule. Click OK.


  7. Complete the print merge operation. For record 2, "This is true" should appear in the merged document.



MORE INFORMATION

For example, using the following sample data file, the following conditional statement incorrectly yields a true result for the first and second records, although only the second record satisfies the condition:

{IF {MERGEFIELD NUMBER} = "1AB" "This is true"}
NOTE: The IF field evaluated only the first two characters (1A) of the numeric string.

Sample Data File


   ---------------------------------
   |  Rec_Num  |Name      |Number  |
   ---------------------------------
   |     1     |John      |1AA     |
   ---------------------------------
   |     2     |Bill      |1AB     |
   ---------------------------------
   |     3     |Fred      |2AA     |
   ---------------------------------
   |     4     |George    |ABC     |
   --------------------------------- 

Additional query words: winword2 numbers strings alphabetic

Keywords : kbdta kbfield winword kbmerge macword word6 winword2 word7 word95
Version : MACINTOSH:6.0,6.0.1,6.0.1a; WINDOWS:2.0,2.0a,2.0a-CD,2.0b,2.0c,6.0,6.0a,6.0c,7.0,7.0a
Platform : MACINTOSH WINDOWS
Issue type : kbhowto


Last Reviewed: January 4, 2000
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.