Microsoft KB Archive/299837

= WD2000: How to Merge a Single Data Source to Multiple Letters with IncludeText =

Article ID: 299837

Article Last Modified on 10/11/2006

-

APPLIES TO


 * Microsoft Word 2000 Standard Edition

-



This article was previously published under Q299837





SUMMARY
When you use the Mail Merge feature of Microsoft Word, you can use only one main document with one data source. However, with IF and AutoText fields, or IF and IncludeText fields, you can simulate merging one data source into several letters.

AutoText fields store your information in AutoText entries. IncludeText fields stores your information in separate letters. Both methods produce the same results.

This article describes how you can use the IncludeText fields to produce several letters using one data source.

For additional information about using the AutoText method instead, click the article number below to view the article in the Microsoft Knowledge Base:

211786 How to Merge a Single Data Source to Multiple Letters Using AutoText Entries



MORE INFORMATION
To merge a single data source to multiple letters using IncludeText fields, follow these steps.

Step 1: Set Up the Mail Merge Main Document
To create a mail merge to produce several different letters to different people based on a particular set of criteria, you must first create and save the separate letters that contain the merge fields you want to use.
 * 1) On the Tools menu, click Mail Merge.
 * 2) In the Main document section of the Mail Merge Helper dialog box, click Create, and then click Form Letters. In the next dialog box that appears, click Active Window.
 * 3) To use an existing data source, click Get Data, and then click Open Data Source. In the Open Data Source dialog box, find your data source, and then click Open.
 * 4) In the message box that appears, click Edit Main Document.
 * 5) Create the first letter. Enter the appropriate merge fields.
 * 6) On the File menu, click Save As, and then name the file. For example, type Letter1 . Click Save.

NOTE: You must know the path to this file; for example, if Letter1 is in the My Documents folder on the C drive, the path is C:\My Documents\Letter1.doc. You will need to enter this information in the main document created later.
 * 1) Change this letter as appropriate for the second letter. Enter merge fields as appropriate and save the file under a different name, such as Letter2.doc.
 * 2) Repeat steps 6 and 7 for each letter that you want to create. When you name the files, use distinct file names, such as &quot;Letter2,&quot; &quot;Letter3,&quot; and so on.

Step 2: Modify the Data Source
Once you create all of the letters as separate files, you need to modify your data source to include a field that will be helpful in identifying which letter you will create for a particular record. To do this, follow these steps:
 * 1) With the last mail merge letter that you created in the &quot;Setting Up the Mail Merge Main Document&quot; section earlier in this article, click Select All on the Edit menu, and then press DELETE to delete everything from the document.
 * 2) On the File menu, click Save As, give it a different file name, such as Main.doc, and then click Save.

This document will become the mail merge main document that you will perform the merge from.
 * 1) On the Tools menu, click Mail Merge. Under Data Source, click Edit, and then click the name of the data file. The Data Form dialog box appears.
 * 2) Click View Source to view the data source in a table format.
 * 3) To create a new field, click the Manage Fields button on the Mail Merge toolbar.
 * 4) In the Field name box, type a field name (for example, type Code ), click Add, and then click OK.
 * 5) Enter a code for each of the records to identify which letter will be used during the merge for that particular record. For example, if you created three letters, for each record in your data source, enter a 1, 2, or 3 in the Code field. Code 1 represents Letter1; Code 2 represents Letter2; Code 3 represents Letter3, and so on.
 * 6) Save the data file, and then click the Mail Merge Main Document button on the Mail Merge toolbar to return to the main document.

Step 3: Modify the Main Document
You need to modify the blank main document (Main.doc) to include IF fields that identify which IncludeText letter will be merged for each particular record.  At the top of the blank document, follow these steps to enter an IF field into the document:  Click the Insert Word Field button on the Mail Merge Toolbar. Click '''If... Then... Else...'''. In the Field Name list, select the field that you created in the data source in the &quot;Step 2: Modifying the Data Source&quot; section earlier in this article (Code in the example in this article). In the Comparison list, click Equal to. In the Compare To box, type a value that you used in the newly created field (Code), such as 1, 2, or 3.</li>  Click OK. NOTE: If you do not see the field code instructions in the document, press ALT+F9 on the keyboard to turn on the field code view.

If you used &quot;Code&quot; for the fieldname and typed in a value of 1, the field code in the document should look like the following:

{IF {MERGEFIELD Code} = 1 &quot;&quot; &quot;&quot;} </li> Click between the first set of two quotation marks, and then click Field on the Insert menu.</li> Select the Links and References category, and then click IncludeText on the Field Names list.</li>  Click in the box that reads INCLUDETEXT, and then type the complete path and file name to the first letter. You must enclose the path in quotation marks and use double backslashes between each drive, directory, and file name.

The finished field code looks similar to the following:

{IF {MERGEFIELD Code} = 1 &quot;{INCLUDETEXT &quot;C:\\MY DOCUMENTS\\LETTER1.DOC&quot; \*MERGEFORMAT}&quot;}

You can delete the second set of quotation marks. They are used for an Else condition that is not needed for this example. </li></ol> </li> Select the complete IF field and copy it. Paste it in the document as many times as there are different letters with corresponding codes. For example, if there are three letters and three codes, paste the field so that there are three copies of it.</li>  In the pasted fields, modify the code used for the comparison value ( 1, 2, and so on) and modify the letter name to be used (Letter1.doc, Letter2.doc, and so on).

If there are three different letters to be used in the merge, the main document looks similar to the following:

{IF {MERGEFIELD Code} = 1 &quot;{INCLUDETEXT &quot;C:\\MY DOCUMENTS\\LETTER1.DOC&quot; \*MERGEFORMAT}&quot;} {IF {MERGEFIELD Code} = 2 &quot;{INCLUDETEXT &quot;C:\\MY DOCUMENTS\\LETTER2.DOC&quot; \*MERGEFORMAT}&quot;} {IF {MERGEFIELD Code} = 3 &quot;{INCLUDETEXT &quot;C:\\MY DOCUMENTS\\LETTER3.DOC&quot; \*MERGEFORMAT}&quot;}

</li> Save the main document.</li></ol>

Step 4: Merge the Documents
With the Main document open, click Mail Merge on the Tools menu, and then click Merge. Choose to merge to a New Document, and then verify that the correct letter is used for the appropriate records in your data source.

When you perform the mail merge, Word produces the letter based on the code the data file has for a particular record. For example, if Record 1 has a Code value of 1, Word produces Letter1. If record 2 has a Code value of 3, Word uses Letter3.

<div class="references_section">