PDA

View Full Version : Solved: Error using Doccmd.transfertext



anandks42
06-23-2008, 02:10 PM
Hi,
I am trying a sample program to transfer contents from a delimited file into a table in access. This is the code I am using:

Sub importfile()
On Error GoTo ferrors
Dim db As database
Dim rec As Recordset
DoCmd.TransferText acImportDelim, , "tblDet", "C:\Anand\Ebook\practice\Access\test.csv", yes
Set db = CurrentDb()
Set rec = db.OpenRecordset("tblDet")
ferrors:
Debug.Print ("sub importfile: " & Err.Number & ": " & Err.Description)
End Sub

This is the error message I am getting:
sub importfile: 2391: Field 'F1' doesn't exist in destination table 'tblDet.'

tbldet has the following structure
Name Emp No Age
(and values for these fields)
This is what test.csv contains:
Name Emp No Age
(and values for these fields)
Please help me debug this error. Thanks!

OBP
06-24-2008, 04:47 AM
That error usually occurs because Access has come across some data that does not fit in with your field names and has assigned it the value of F1.
Perhaps one or more lines in the file have more commas than others.
Have you checked out the data to see if there is anything obvious?

anandks42
06-24-2008, 10:33 PM
Was able to figure it out. Needed to give the import specification