Module works in one db, but not other

G

Guest

I used the following module to import multiple ".csv" files. It works in two
separate databases. Third database, I get "run time error 3001, invalid
argument." Stepped thru and all variables are correct.


Sub IsImported()
Dim MyPath, MyFile
MyPath = "C:\Documents and Settings\Scott\My
Documents\EagleVisionSolutions\Campaigns\Reference USA\Missouri not St Louis
not Kansas City\"
MyFile = Dir(MyPath + "*.csv", vbNormal)
'MyName = MyPath + MyFile

Do While MyFile <> ""

DoCmd.TransferText acImportDelim, , "NewNotKCStl", MyFile, -1
MyFile = Dir
Loop
End Sub
 
D

Douglas J. Steele

I don't know why you're getting that specific error message, but your code
is not passing the correct file name to the TransferText command. Perhaps
fixing that will solve the problem.

Since Access won't necessarily know where the file exists, you need to pass
it the complete path to the file, not just the file name:

DoCmd.TransferText acImportDelim, , "NewNotKCStl", MyPath & MyFile, -1

A couple of other comments.

It would be (slightly) more efficient to declare MyPath and MyFile as
strings:

Dim MyPath As String, MyFile As String

Also, it's usually better to use & as the concatenation operator for
strings, not +.
 
G

Guest

I attempted to add the path at one time, but it didn't seem to work. I
didn't try the concantenation sign, they didn't teach me that in class. I'll
try it. Thanks a lot.
 
G

Guest

I don't know if this has anything to do with it, but I keep getting "invalid
argument" errors even when I am attempting to save or delete objects such as
modules and tables. Is my Access corrupted? I've attempted "Detect and
Repair" a couple of times, but it doesn't seem to work.
 
Top