CSV import error only with code

G

gg

When I import a csv file into an existing table manually ( file-import etc.)
all is well. When I import the same file into the same table using code, I
get a type conversion error for one field. This field is typically contains
numbers, but some numbers in some fields are preceeded by alpha characters.
USA 12345 for example. Any field with the preceeding alphas gets rejected
and shows as an import error. The recieving table field is text with zero
length allowed. Code for importing is DoCmd.TransferText acImportDelim,
"ROSspec", "99js", mypath & "Myfile.csv", True, "". Using AC 2000 with
W2000
Help-driving me nuts-thanks in advance
 
P

Piet Linden

When I import a csv file into an existing table manually ( file-import etc.)
all is well.  When I import the same file into the same table using code, I
get a type conversion error for one field.  This field is typically contains
numbers, but some numbers in some fields are preceeded by alpha characters.  
USA 12345 for example.  Any field with the preceeding alphas gets rejected
and  shows as an import error.  The recieving table field is text with zero
length allowed.  Code for importing is  DoCmd.TransferText acImportDelim,
"ROSspec", "99js", mypath & "Myfile.csv", True, "".    Using AC 2000 with
W2000
 Help-driving me nuts-thanks in advance  

Do an import manually once, and create an import specification and
save it. Then use the ImportSpec with the TransferText command, and
it should work fine. The problem is that Access looks at the first ?
rows in the table and uses that to determine the field type, and it's
guessing wrong. So if you "tell it" what kind of data is in the field
(by using the Import Spec), it will work fine every time.
 

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