Microsoft KB Archive/208380

= ACC2000: TransferSpreadsheet May Not Allow the Table Append Operation =

Article ID: 208380

Article Last Modified on 6/24/2004

-

APPLIES TO


 * Microsoft Access 2000 Standard Edition

-



This article was previously published under Q208380



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

This article applies to a Microsoft Access database (.mdb) and to a Microsoft Access project (.adp).



SYMPTOMS
When you append data from a spreadsheet to an existing table by using a TransferSpreadsheet macro action or a TransferSpreadsheet method in Visual Basic for Applications, you may receive one of the following error messages:

Field 'F1' doesn't exist in destination table ' .'

Microsoft Access was unable to complete the append operation. The destination table must contain the same fields as the table you are pasting from.

-or-

Run-time error '2391':

Field 'F1' doesn't exist in destination table ' .'



CAUSE
The first row of the spreadsheet file does not contain field names; therefore, Microsoft Access assumes the fields are named "F1," "F2," and so on.



RESOLUTION
You can use one of the following two methods to work around this behavior. You can import the spreadsheet into a new table, and then append that data in Microsoft Access; or you can change the spreadsheet to include field names in the first row.

Method 1

 * 1) Import the spreadsheet into a new table named tblTemp.
 * 2) Create an append query to append the data in the tblTemp table to your existing table.
 * 3) Run the append query.
 * 4) Delete the tblTemp table.

Method 2
 In Microsoft Excel, insert a new first row in the spreadsheet. In this row, add field names that match the field names in the existing Microsoft Access table. In the macro, change the Has Field Names argument to Yes, for example:

Transfer Type: Import

Spreadsheet Type:

Table Name:

File Name: \

Has Field Names: Yes

  If you are using code, the HasFieldNames argument should be set to True, for example: DoCmd.TransferSpreadsheet acImport, _ , "", _ ", True                   



Steps to Reproduce Behavior
CAUTION: If you follow the steps in this example, you modify the sample database Northwind.mdb. You may want to back up the Northwind.mdb file and follow these steps on a copy of the database.

 Start Microsoft Excel and create a spreadsheet with the following data:

A1: 9

A2: Express

A3: 800-123-4567

B1: 10

B2: US Mail

B3: 800-569-4568

</li> Save the spreadsheet as C:\test1.xls.</li> Start Microsoft Access, and then open the sample database Northwind.mdb or the sample project NorthwindCS.adp.</li> Create a macro with the TransferSpreadsheet action and the following action arguments:

Transfer Type: Import

Spreadsheet Type: Microsoft Excel 8-9

Table Name: Shippers

File Name: C:\test1.xls

Has Field Names: No

</li> Save the macro as TestImport, and then run the macro. Note that you receive the error mentioned in the "Symptoms" section.</li></ol>

<div class="references_section">