Import spec is "Empty" in TransferText command?

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
 
N

Nikos Yannacopoulos

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
 
G

Guest

What is the syntax for the quotes:
"A2Import" does not work, getting nothing
when the cursor is placed over it in debug.
 
J

JumboShrimps

DoCmd.TransferText acLinkDelim, A2Import,
strCSVFileName, strCSVFileName

-code from bottom of post.
Need to know how to pass A2Import specs
to docmd.transferText....
 
N

Nikos Yannacopoulos

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
 

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