Microsoft KB Archive/198919

= ACC2000: How to Import a Word Table Containing Carriage Returns =

Article ID: 198919

Article Last Modified on 6/30/2004

-

APPLIES TO


 * Microsoft Access 2000 Standard Edition

-



This article was previously published under Q198919



Moderate: Requires basic macro, coding, and interoperability skills.

For a Microsoft Access 2002 version of this article, see 290169.



SUMMARY
When you import a Microsoft Word table that contains carriage returns in its cells, the table is not imported correctly because Microsoft Access interprets each carriage return/line feed as a new record delimiter. To avoid this problem, you can surround the contents of the table cells with quotation marks so that the carriage returns are interpreted as part of the text in the cell, and not as the end of a record.

This article shows you how to export a Word table that contains carriage returns into a tab-delimited text file that you can import into Microsoft Access.



MORE INFORMATION
In this example, you convert the table and its contents to a tab-delimited format; then, you save the file as text and import it into a Microsoft Access database. The techniques in this example assume that you know how to create a table in Microsoft Word, and that the table is the only object in your document.

Creating the Microsoft Word Table
 Start Microsoft Word and create a new blank document. Insert a table with three columns and four rows.  Enter the following data in the table, including the column headings. Press the ENTER key at the end of the first line in each address so that the city, state, and postal code appear on a separate line:

     +-+--+--+ |FirstName   |LastName      |Address               | +-+--+--+     |Bob          |White         |12 Rocky Rd.          | |            |              |Anywhere, TX  43210   | +-+--+--+     |Sal          |Vation        |1000 Pearly St.       | |            |              |Noble, NM  33333      | +-+--+--+     |Art          |Work          |120/98 Scenic Way     | |            |              |Goodview, WI  12332   | +-+--+--+                    Save the document as Address.doc, and leave the document open.

Formatting the Document as Tab-Delimited Text
 Temporarily replace all paragraph marks (carriage returns) in the document with a character that is not already used in your table, such as the tilde (~). To do so, follow these steps:  On the Edit menu, click Replace.</li> In the Find And Replace dialog box, type ^p in the Find what box and type ~ in the Replace with box.</li> Click Replace All.</li> When you receive a message that the search and replace is complete, click OK.</li> Close the Find And Replace dialog box.</li></ol> </li> Convert the table to tab-delimited text format. To do so, follow these steps:  Click in any cell in the table.</li> On the Table menu, click Select Table.</li> On the Table menu, click Convert Table to Text.</li> In the Convert Table to Text dialog box, click Tabs, and then click OK.</li></ol> </li> Type a quotation mark (") at the very beginning of the document, to the left of the word "FirstName." This is the first text qualifier that will surround each field in the table.

NOTE: If the text in your table contains any quotation marks, you must remove or replace them with another character, such as an apostrophe ('), before you proceed; otherwise, the table will not be imported correctly.</li> Replace all paragraph marks in the document with a paragraph mark surrounded by quotation marks. To do so, follow these steps:  <li>On the Edit menu, click Replace.</li> <li>In the Find And Replace dialog box, type ^p in the Find what box and type ^p in the Replace with box.</li> <li>Click OK when you receive a message that the search and replace is complete.</li> <li>Close the Find And Replace dialog box.</li></ol> </li> <li>Replace all TAB characters in the document with a TAB character surrounded by quotation marks. To do so, follow these steps: <ol style="list-style-type: lower-alpha;"> <li>On the Edit menu, click Replace.</li> <li>In the Find And Replace dialog box, type ^t in the Find what box and type ^t in the Replace with box.</li> <li>Click Replace All.</li> <li>Click OK when you receive a message that the search and replace is complete.</li> <li>Close the Find And Replace dialog box.</li></ol> </li> <li>Restore the original paragraph marks in your document by replacing all tildes (~) with paragraph marks. To do so, follow these steps: <ol style="list-style-type: lower-alpha;"> <li>On the Edit menu, click Replace.</li> <li>In the Find And Replace dialog box, type ~ in the Find what box and type ^p in the Replace with box.</li> <li>Click Replace All.</li> <li>Click OK when you receive a message that the search and replace is complete.</li> <li>Close the Find And Replace dialog box.</li> <li>On the File menu, click Save As.</li> <li>In the Save As dialog box, select Text Only in the Save As Type box, and type Address.txt in the File Name box. Click Save.</li> <li>Close the document and quit Word.</li></ol> </li></ol>

Importing the Table into Access

 * 1) Start Access and open the sample database Northwind.mdb.
 * 2) On the File menu, point to Get External Data, and then click Import.
 * 3) In the Import dialog box, select Text Files in the Files Of Type box, and then select Address.txt in the appropriate folder. Click Import.
 * 4) Click Next on the first screen of the Import Text Wizard. Click to select the First Row Contains Field Names check box on the second screen of the Wizard, and then click Finish to import the table.
 * 5) Open the Address table in Datasheet view.
 * 6) On the Format menu, click Row Height. Set the row height to 25, and then click OK.
 * 7) Click anywhere in the Address column, and then on the Format menu, click Column Width. Set the column width to 50, and then click OK. Note that you can see both lines of each address, and that each address includes the carriage return.

<div class="references_section">