Problem when importing csv file

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
 
J

John Nurick

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.
 
G

Guest

Hi John,

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

Thank you very much!

Huan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top