Import spec is "Empty" in TransferText command?

  • Thread starter Thread starter JumboShrimps
  • Start date Start date
J

JumboShrimps

This codes links all .csv files in a
directory to my database.
For some reason, even though the "A2Import"
spec exists, and the specification does work
when the .csv files
are linked manually (there are hundreds of them,
so that's not possible) - when I place the
cursor over the "A2Import" in debug mode,
I get "Empty".
I need to read the column headers (and have the field
types match the specification) in the .csv file,
and without the Import specification,
it's not happening. All .csv files in the
directory ARE successfully linked,
with column headers F1,F2,F3,F4, etc instead
of the right column names, and with incorrect
column formats.


dim strCSVFileName as string

strCSVFileName = Dir("G:\Data\*.csv")
Do While strCSVFileName <> ""
DoCmd.TransferText acLinkDelim, A2Import, strCSVFileName,
strCSVFileName
strCSVFileName = Dir()
Loop
 
The import specification argument is a string, so you need to enclose it in
quotes for Access to treat it as such. Without quotes Access treats it like
a variable, and because it has not been assigned a value, you can see it is
null in debugging.

HTH,
Nikos
 
What is the syntax for the quotes:
"A2Import" does not work, getting nothing
when the cursor is placed over it in debug.
 
DoCmd.TransferText acLinkDelim, A2Import,
strCSVFileName, strCSVFileName

-code from bottom of post.
Need to know how to pass A2Import specs
to docmd.transferText....
 
If your import spec name is A2Import, then the synatx is
DoCmd.TransferText acLinkDelim, "A2Import", TableName, FileName

You still wouldn't see anything in the spec name in debug mode... it is a
string, not a variable!

Also, make sure you have the correct arguments for table name and file name
(also strings, so also in quotes, unluess using string or variant
variables - which is what you seem to be doing). In your code you are using
the same variable for the table name and the file name; can this be the
case? the file name shouls include the path, so quite unlikely...

Nikos
 
Back
Top