Problem when importing csv file

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I am having a problem to import csv file to Access table. It says "Field F1
does not exist in myTable table". Here is the code I use
DoCmd.TransferText acImportDelim, , "MyTable", TableFileName, False

I tried to use wizard to import. It worked fine without import
specification. However, if I use specification to import. It gives me same
error. What did I do wrong? The problem is I need to use VBA code to import
since the file name is not fixed.
Please advise.

Thanks in advance.

Huan
 
Hi Huan,

This error can occur when you import data to an existing table from a
CSV file that does not have a header row containing the field names.

If the text file doesn't include field names, the Jet database engine's
Text ISAM assigns default names of F1, F2, ...

But when you created the table using the text import wizard, either you
assigned your own field names, or you let Access assign its default
names Field1, Field2, ...

One solution is to import the data once manually and create and save an
import specification as you do. Then pass the name of the specification
to TransferText.

Another is to use a linked table to access the text files. This will
have the default names; you can then use an append query to append the
data from the linked table to myTable, adjusting the field names en
route.
 
Hi John,

It worked very well when I saved import spec and use it for export!

Thank you very much!

Huan
 
Back
Top