 |
| Access VBA Discuss 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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

May 1st, 2007, 07:21 AM
|
|
Registered User
|
|
Join Date: Mar 2007
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Run Time Error 3011
Help!
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"??
Code follows:
fileName = Dir("c:\downloads\*.csv", vbNormal)
Do While fileName <> ""
DoCmd.TransferText
acImportDelim, "ImportSpecs", "rawCSV", fileName, False '
crashes on this line
Call GenerateReport
Loop
|
|

May 2nd, 2007, 12:25 PM
|
|
Friend of Wrox
|
|
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
|
|
This is not all the code here to import a text file. Is that what you are trying to do and it is not working (the import part?)
mmcdonal
|
|

May 2nd, 2007, 03:03 PM
|
|
Registered User
|
|
Join Date: Mar 2007
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
|

May 3rd, 2007, 06:38 AM
|
|
Friend of Wrox
|
|
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
|
|
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\")
Sub ShowSubFolders(Folder)
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
End If
Next
ShowSubFolders SubFolder
Next
End Sub
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.
The code you posted is incomplete to do this.
HTH
mmcdonal
|
|
 |