Access VBADiscuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
Run Time Error 3011
The Microsoft Jet database engine could not find the object 'bla-bla-bla' Make sure the object exists and you spell its name and the
path name correctly."
I have a directory with many files, each of which I
import to Access, and then a generate report). The
offending code that produces the error is listed below,
but the error occurs ONLY the first time that it is run
after opening the mdb file. If I import manually once,
then the code runs perfectly. Is there a way to do this
without having to "prime the pump"??
fileName = Dir("c:\downloads\*.csv", vbNormal)
Do While fileName <> ""
acImportDelim, "ImportSpecs", "rawCSV", fileName, False '
crashes on this line
Actually....for the sake of stating this problem..there is enough code shown. After the DIR command....and you drop down to the
acImportDelim, "ImportSpecs", "rawCSV", fileName, False ' line...it blows up with the Run Time Error 3011 stating that it cannot find the file that is contained in the value of variable "FileName". It is a problem since it was the DIR command that populated the value into the variable "Filename". Yet...if you import a file "manually" first....this code or code like it....WILL WORK FINE! That's the dilemma of this error. This error is raised on this bit of code, UNTIL, you go ahead and import a file manually 1st.
You can recurse a folder or folders, and take the filenames, either one at a time, or all at once into an array. For example, this script recurses every folder on my desktop, and shows me every jpg file by path and filename:
Set FSO = CreateObject("Scripting.FileSystemObject")
ShowSubFolders FSO.GetFolder("C:\Documents and Settings\MyUserName\Desktop\")
For Each SubFolder In Folder.SubFolders
Set demofolder = FSO.GetFolder(SubFolder.Path)
Set filecoll = demofolder.Files
For Each fil in filecoll
sJpg = Right(fil.Name, 3)
If sJpg = "jpg" Then
WScript.Echo SubFolder.Path & ": " & fil.Name
Using this, you can find the csv files in your folder structure, or just use a single folder, and then you can try to import them, or you can read them line by line. I do both in various applications.