Microsoft KB Archive/318115

= How to create a form letter by using information from an Access database in Word 2002 =

Article ID: 318115

Article Last Modified on 8/31/2007

-

APPLIES TO


 * Microsoft Word 2002 Standard Edition
 * Microsoft Access 2002 Standard Edition

-



This article was previously published under Q318115



SUMMARY
This article explains how to use the Mail Merge feature in Microsoft Word 2002 to create and print form letters that call data from a Microsoft Access database. This article contains instructions about using the Customers table in the Northwind sample database that is supplied with Access.

When you use the Word 2002 Mail Merge feature, Word merges a main document with a recipient list (data file) to generate a set of output documents (form letters):
 * The main document contains the basic text that is the same in all of the output documents. It may contain a letterhead, text, and instructions within merge fields for inserting text (such as recipient names and addresses) that varies from one output document to another.
 * The recipient list is a database -- for example, an Access 2002 database file, that contains the data that is to be merged into the output documents. This database is typically a list of names, addresses, phone numbers, and other variables.
 * The output documents are the result of the mail-merge operation. The text in an output document can be the same in all output documents, but you can apply formatting to specific documents.

Step 1 - Prepare the Access Database
Before you proceed with the Mail Merge Wizard, decide how you want to use your Access database for the form letter in Word 2002. There are several methods that you can use:
 * Use an Access Table or Query in a Word Document
 * Export an Access Table or Query Directly into a Word Document
 * Export Your Data from Access as a Word Data Source
 * Copy and Paste Access Data as a Word Data Source

Use an Access Table or Query in a Word Document
You can use an Access table or query directly from within a mail-merge operation in Word, without making any additional modifications to the table or query.

To use an Access query or table as a Word data source, continue with the steps outlined in the Step 2 - Set Up the Main Document section of this article.

Export an Access Table or Query Directly into a Word Document
You can use Access to embed data from an Access table or query directly into a Word document. To embed data from an Access database in a Word document, follow these steps:
 * 1) Open your database, and then select the table or query that contains the data that you want to embed in a Word document.
 * 2) On the Tools menu, click Office Links, and then click Merge It With MS Word (or click Merge It With MS Word on the Office Links toolbar).

The Microsoft Word Mail Merge Wizard starts.
 * 1) Select the Link your data to an existing Microsoft Word document or Create a new document and then link your data to it option. If you select Link to an existing Microsoft Word document, the wizard will ask for the document location. When you finish, click OK.
 * 2) The wizard starts Word and then activates a mail merge link to your table or query.

Proceed to the Step 2 - Set Up the Main Document section of this article.

Export Your Data from Access as a Word Data Source
To export and use your data from Access as a Word data source, follow these steps:  In Access, open your database table or query. On the File menu, click Export. In the Export Table or Export Query dialog box, follow these steps:  In the Save as type box, click Microsoft Word Merge (*.txt). In the File name box, type a name for your exported file. In the Save in box, click the folder in which you want to save the file. </li> Click Export All.

Access now exports your table or query result as a tab-delimited text file.</li> Close your database, and then quit Access. Continue with the steps outlined in the Step 2 - Set Up the Main Document section of this article. When you reach the Step 3 - Specify the Microsoft Access Data Source section of this article, select the exported tab-delimited text file to continue your Word mail-merge operation.</li></ol>

Copy and Paste Access Data as a Word Data Source
To copy, paste, and use Access data as a Word data source, follow these steps:
 * 1) Open your Access database table or query.
 * 2) On the Edit menu, click Select All Records.
 * 3) On the Edit menu, click Copy.
 * 4) Open a new, blank document in Word.
 * 5) Use one of the following methods.


 * Method 1: Save Data as a Table
 * On the Edit menu, click Paste Special. In the Paste Special dialog box, click Formatted Text (RTF) under As.

The information from your Access table or query is pasted into a Word table.
 * Save this new file as a Word document.

This new file is your new Word data source.
 * Continue with the steps outlined in the Step 2 - Set Up the Main Document section of this article. When you reach the Step 3 - Specify the Access Data Source section of this article, select the Word document to continue your Word mail-merge operation.
 * Method 2: Save Data in Tab-Delimited Format
 * On the Edit menu, click Paste Special.
 * In the Paste Special dialog box, click Unformatted Text, and then click OK.

The information from your Access table or query is pasted into your Word document as tab-delimited text.
 * On the File menu, click Save As.
 * In the Save As dialog box, click Plain Text in the Save as type box.
 * In the File name box, type a name for your exported file.
 * In the Save in box, select the folder in which you want to save the file, and then click Save.
 * Under Text encoding, click Windows (Default).
 * Close your Word data source document.
 * Continue with the steps outlined in the Step 2 - Set Up the Main Document section of this article. When you reach the Step 3 - Specify the Access Data Source section of this article, select the tab-delimited text file that contains your table file to continue your Word mail-merge operation.

Step 2 - Set Up the Main Document
 Start Word 2002, point to Letters and Mailings on the Tools menu, and then click Mail Merge Wizard.</li> Under Select document type, click Letters.

The active document becomes the main document (the document that contains the text and graphics that are the same for each version of the merged document -- for example, the return address or salutation in a form letter).</li> Click Next: Starting document.</li> Do one of the following: <ul> Start with the document currently shown in the document window. To do this, click Use the current document.

You can then either type the letter in the document window or wait until the wizard prompts you to do so in a later step.</li> Start with a template.  Click Start from a template.</li> Click Select template.</li> In the Select Template dialog box, click the Mail Merge tab, select the template that you want, and then click OK.</li></ol> </li> Start with an existing document.  Click Start from existing document.</li> <li>In the Start from existing box, select the document that you want, and then click Open.</li> <li>If you do not see the document, click More files, and then click Open. In the Open dialog box, locate the document that you want, and then click Open.</li></ol> </li></ul> </li> <li>Click Next: Select recipients.</li></ol>

Step 3 - Specify the Access Data Source
<ol> <li>Under Select recipients, click Use an existing list.</li> <li>Click Browse. By default, Word opens the My Data Sources folder.</li> <li>In the Select Data Source dialog box, locate and then select the file that you want to use. For this example, you can use the Customers table in the Northwind Sample database that is included with Access. By default, the Northwind Sample database is installed in the following location:

C:\Program Files\Microsoft Office\Office10\Samples\Northwind.mdb

</li> <li>In the Select Table dialog box, select the table or query that you want to use. For this example, select the Customers table, and then click Open.</li> <li>All of the entries in the data source appear in the Mail Merge Recipients dialog box, where you can refine the list of recipients to include in the merge.</li></ol>

NOTE: You can use Microsoft Query to create a query and retrieve the data that you want from an Access database. You can create a simple query by using the Query Wizard, or you can create a more complex query by using the advanced features of Microsoft Query.

For example, if you want to insert database information, display the Database toolbar, click Insert Database, and then click Get Data. In the Select Data Source dialog box, click MS Query on the Tools menu.

When Microsoft Query starts, the Microsoft Office Assistant provides help in constructing your query.

If you do not see the Office Assistant in Microsoft Query, close the Choose Data Source dialog box, and then click Microsoft Query Help on the Help menu.

Step 4 - Select the Recipients
<ol> <li>In the Mail Merge Recipients dialog box, select the recipients that you want to include. To do this, use any of the following methods: <ul> <li>Use the check boxes to designate recipients.

This method is most useful if your list is short. Click to select the check boxes next to the recipients that you want to include, and then click to clear the check boxes next to the recipients that you want to exclude.

NOTE: If you know that you want to include most of the list in your merge, click Select All, and then clear particular records. Similarly, if you want to include only a few records in the list, click Clear All, and then select the records that you want.</li> <li>Sort items in the list.

This is useful if you want to see items in alphabetical or numeric order. Click the column heading of the item that you want to sort by. For example, if you want to display the list alphabetically by last name, click the Last Name column heading.</li> <li>Filter items in the list.

This is useful if the list contains records that you know you do not want to see or include in the merge. After you have filtered the list, you can use the check boxes to include and exclude records, as described in the previous method. To filter the list, follow these steps: <ol style="list-style-type: lower-alpha;"> <li>Click the arrow next to the column heading of the item that you want to filter by.</li> <li>Click any of the following: <ul> <li>(Blanks) displays all the records in which the corresponding field is blank.</li> <li>(Nonblanks) displays all the records in which the corresponding field contains information.</li> <li>If your data source contains records that share the same information, and there are 10 or fewer unique values in the column, you can filter by specific information. For example, if there are multiple addresses that list Australia as the country or region, you can filter on Australia.</li></ul> </li></ol> </li> <li>The Mail Merge Recipients dialog box displays only the designated records. To display all the records again, click (All).</li></ul>

NOTES: <ul> <li>For advanced sorting and filtering, click the arrow next to any column name, and then click (Advanced). Use the Filter Records and Sort Records tabs to set up the sorting or filtering query that you want.</li> <li>If you have installed address-validation software, you can click Validate in the Mail Merge Recipients dialog box to validate your recipients' addresses.</li></ul> </li> <li>For this example, click Clear All, and then select the first two customers on the list.</li> <li>Click OK to return to the Mail Merge Wizard.

Word will use the recipients that you designated for the merge.</li> <li>Click Next: Write your letter.</li></ol>

Step 5 - Complete the Letter and Add Merge Fields
If you have not already done so, in the main document, type the text that you want to appear in every form letter.

Insert Merge Fields
Insert merge fields where you want to merge names, addresses, and other information from the data source. To insert merge fields, follow these steps: <ol> <li>In the main document, click where you want to insert the field.</li> <li>Insert any of the following: <ul> <li>Address block with name, address, and other information <ol style="list-style-type: lower-alpha;"> <li>Click Address block.</li> <li>In the Insert Address Block dialog box, select the address elements that you want to include and the formats that you want, and then click OK.

For help on an option, click the question mark, and then click the option.</li> <li>If the Match Fields dialog box appears, Word may not be able to find some of the information it needs for the address block. Click the arrow next to (not available), and then select the field from your data source that corresponds to the field required for the mail merge.</li></ol> </li> <li>Greeting line <ol style="list-style-type: lower-alpha;"> <li>Click Greeting line.</li> <li>Select the greeting line format, which includes the salutation, name format, and following punctuation.</li> <li>Select the text that you want to appear in cases where Word cannot interpret the recipient's name -- for example, when the data source contains no first or last name for a recipient, but only a company name.</li> <li>Click OK.</li> <li>If the Match Fields dialog box appears, Word may not be able to find some of the information it needs for the greeting line. Click the arrow next to (not available), and then select the field from your data source that corresponds to the field required for the mail merge.</li></ol> </li> <li>Other fields of information <ol style="list-style-type: lower-alpha;"> <li>Click More items.</li> <li>Do one of the following: <ul> <li>To select from address fields that will automatically map to corresponding fields in your data source, even if the data source's fields do not have the same name as your fields, click Address Fields.</li> <li>To select from fields that always take data directly from a column in a database, click Database Fields.</li></ul> </li> <li>In the Fields box, click the field that you want.</li> <li>Click Insert, and then click Close.</li> <li>If the Match Fields dialog box appears, Word may not be able to find some of the information it needs to insert the field. Click the arrow next to (not available), and then select the field from your data source that corresponds to the field required for the mail merge.

Note: If you insert a field from the Database Fields list, and then later switch to a data source that does not have a column with the same name, Word cannot insert that field information into the merged document.</li></ol> </li> <li>Electronic postage

To add electronic postage, you must first install an electronic postage program, such as one you purchased from a service on the Web. To use electronic postage, follow these steps: <ol style="list-style-type: lower-alpha;"> <li>Click Electronic postage.

If you do not have an electronic postage program installed, Word prompts you to install one if you want.</li> <li>Insert the postage according to the program's instructions.</li></ol> </li> <li>Postal bar code

You must select a letter or envelope type that supports the POSTNET bar code. To use the Postal bar code, follow these steps: <ol style="list-style-type: lower-alpha;"> <li>Click Postal bar code.</li> <li>In the Insert Postal Bar Code dialog box, select the appropriate address fields.

NOTE: The Postal bar code option appears only if you are using the U.S. language version of Word.</li> <li>Repeat steps a and b for all the fields that you want to insert.NOTES: <ul> <li>You cannot type merge field characters ({ }) by using the &quot;{&quot; or &quot;}&quot; keys or insert them by using the Symbol command on the Insert menu.</li> <li>If the merge fields appear inside braces, such as { MERGEFIELD City }, Word is displaying field codes instead of field results. This does not affect the merge operation, but if you want to display the results instead, right-click the field code, and then click Toggle Field Codes on the shortcut menu.</li></ul> </li></ol>

For this example, insert the AddressBlock and GreetingLine fields and text, so that your first page appears similar to the following:

'''February 26, 2002

<<AddressBlock>>

<<GreetingLine>>

Type your letter here.

Sincerely,

Type your name here

'''

</li></ul>

NOTE: You can also use the Mail Merge toolbar to insert merge fields, work with your mail merge main document, or to run a mail merge. To display the Mail Merge toolbar, point to Letters And Mailings on the Tools menu, and then click Show Mail Merge Toolbar. The Mail Merge toolbar provides additional commands not included in the Mail Merge wizard task panes. For example, you can use the Insert Word Field menu on the Mail Merge toolbar to insert Word fields for controlling the merge process (for example, an IF field that inserts text only if a particular merge field has a specified value). Or, you can click Check For Errors to direct Word to run the mail merge and report any errors contained in the main document.</li></ol>

Change the Format of the Merged Data
To format merged data, you have to format the merge fields in the main document. Do not format the data in the data source, because its formatting is not retained when you merge the data into the document. To change the format of the merged data, follow these steps:
 * 1) In the main document, select the field that contains the information you want to format, including the enclosing merge field characters (<<>>).
 * 2) On the Format menu, click Font, and then select the options that you want.

Formatting by Using Field Codes
To control other aspects of formatting, press ALT+F9 to display field codes, and then add switches to the merge fields. When you are working with fields, a switch is a special instruction that causes a specific action to occur. Generally, a switch is added to a field to modify a result.

For example:
 * 1) To display the number &quot;34987.89&quot; as $34,987.89, add the Numeric Picture switch (\#).
 * 2) To print client names in uppercase letters, add the Format switch (\* UPPER).
 * 3) To make sure that the merged information has the same font and point size that you apply to the merge field, add the (\* MERGEFORMAT) switch.

Step 6 - Saving the Document
After you have completed the main document and inserted all of the merge fields, save the document before proceeding:
 * 1) On the File menu, click Save As.
 * 2) Name the document, and then click Save.
 * 3) Click Next: Preview your letters.

back to the top

Step 7 - Preview the Letters and Fine-Tune the Recipient List
When the wizard displays the Step 5 Mail Merge task pane, it replaces each of the merge fields in the main document with the actual text from the first entry of the recipient list, so that you can see how your first output document will appear.

For example, if you were to continue using the sample database shown earlier, the first page should appear similar to the following after you click Next: Preview your letters:

'''February 26, 2002

Alfreds Futterkiste

Obere Str. 57

Berlin 12209

Dear Alfreds Futterkiste,

Type your letter here.

Sincerely,

Type your name here'''

To preview additional entries, do either of the following:
 * To preview the items in order, click the left or right arrow buttons.

-or-
 * To locate and preview a specific item, click Find a recipient, and then enter the search criteria in the Find Entry dialog box.

Fine-tune the recipient list, as appropriate to your situation. To do so, use one of the following methods:
 * To exclude a particular recipient from the merge, click Exclude this recipient.

-or-
 * To change the list of recipients, click Edit recipient list, and then make your changes in the Mail Merge Recipients dialog box.

Step 8 - Complete the Merge
To complete the merge, use any of the following methods.

Personalize Individual Letters
To personalize individual items, you actually complete the merge, and then edit the information that you want in the resulting merged document:
 * 1) Click Edit individual letters.
 * 2) In the Merge to New Document dialog box, select the records that you want to merge.
 * 3) Click OK.

Word creates and then opens a new merged document. Your main document also remains open, and you can switch back to it if you want to make a change to all the documents.
 * 1) Scroll to the information that you want to edit, and then make your changes.
 * 2) Print or save the document just as you would any regular document.

Print the Letters
To print the letters, do either of the following:
 * If you personalized the items, and the merged document is active, follow these steps:
 * On the File menu, click Print.
 * Select the options that you want.
 * If you want to print directly from the Mail Merge Wizard, follow these steps:
 * In step 6 of the Mail Merge Wizard (Complete the merge), click Print.
 * In the Merge to Printer dialog box, do one of the following, and then click OK:
 * To print all the documents, click All.
 * To print the document that you see in the document window, click Current record.
 * To print a range of documents, click From, and then type the record numbers in the From and To boxes.
 * In the Print dialog box, select the options that you want.

Save the Merged Letters for Later Use
If you want to edit merged letters or save them for later use, you can collect them into a single document. To do this, follow these steps: <ol> <li>Click Edit individual letters.</li> <li>In the Merge to a New Document dialog box, do one of the following, and then click OK: <ul> <li>To merge all the documents, click All.</li> <li>To merge only the document that you see in the document window, click Current record.</li> <li>To merge a range of documents, click From, and then type the record numbers in the From and To boxes.</li></ul>

Word opens a single new document that contains all the individual letters. You can then save the document for later use, just as you would any regular document.</li></ol>

<div class="references_section">