ACC: TransferSpreadsheet May Not Allow Table Append (153812)
The information in this article applies to:
- Microsoft Access 2.0
- Microsoft Access for Windows 95 7.0
- Microsoft Access 97
This article was previously published under Q153812
Moderate: Requires basic macro, coding, and interoperability skills.
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 the following error message:
Field 'F1' doesn't exist in destination table '<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.
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- Import the spreadsheet into a new table named tblTemp.
- Create an append query to append the data in the tblTemp table to your
existing table.
- Run the append query.
- 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: <your type>
Table Name: <table in your database>
File Name: <name of file, including path>
Has Field Names: Yes
- If you are using code, the HasFieldNames argument should be set to True,
for example:
NOTE: In the following sample code, an underscore (_) at the end of a
line is used as a line-continuation character. Remove the underscore
from the end of the line when re-creating this code in Access Basic.
DoCmd.TransferSpreadsheet acImport, _
<number of type of file to import>, "<table in your database>", _
"<name of file including path>", True
REFERENCES
For more information about unexpected behavior with TransferSpreadsheet,
see the following article in the Microsoft Knowledge Base:
147785 ACC: Imported MS Excel Spreadsheet May Have Blank Columns
Modification Type: | Major | Last Reviewed: | 5/9/2003 |
---|
Keywords: | kb3rdparty kberrmsg kbinterop kbprb KB153812 |
---|
|