p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/)
-   Access VBA (http://p2p.wrox.com/access-vba-80/)
-   -   Access 2007 Run Time Error 3011 (http://p2p.wrox.com/access-vba/86826-access-2007-run-time-error-3011-a.html)

Luckdress February 28th, 2012 08:37 PM

Access 2007 Run Time Error 3011
 
Can someone please help? I am trying to import all text files in a folder to an Access dB, but I am getting an error when I run the code below.

Error 3011 -"The Microsoft Office Access database engine could not find the object (filename). Make sure the object exists and that you spell the name and the file path name correctly",
I am passing the full path name to the transfer function using a textbox named txtImportPath1 on a form. The textbox is populated by browsing to the folder and picking up the full path.
The error message picks up the name of the first text file in this folder that it says it cannot find.
Please help!

Code:

strFolderPath = Me.txtImportPath1
    Set objFS = CreateObject("Scripting.FileSystemObject")
   
    If objFS.FolderExists(strFolderPath) = False Then
            MsgBox strFolderPath & " Folder Not Found ", vbCritical, "File Import"
            Exit Sub
    End If
   
    Set objFolder = objFS.GetFolder(strFolderPath)
    Set objFiles = objFolder.files
        For Each objF1 In objFiles
        If Right(objF1.Name, 3) = "TXT" Then
             
    On Error Resume Next
    ' Drop previous Temp table before linking to the new text file
    ' If table not found go to next line
      DoCmd.RunSQL "DROP TABLE tbl_TempWKS"
   
        ' Link to the text file and import file to the specified table using the specs provided
      DoCmd.TransferText acLinkDelim, "WKSpecs", "tbl_TempWKS", objF1.Name, True


disel2010 February 29th, 2012 02:42 PM

Hi,

to be sure to work with the full path for the file, try using
Code:

objF1.Path

Luckdress March 1st, 2012 12:24 PM

Quote:

Originally Posted by disel2010 (Post 282060)
Hi,

to be sure to work with the full path for the file, try using
Code:

objF1.Path

Thank you disel2012. It turned out that my objF1.Name did not capture the full path. I added strFolderPath and it worked!
Yesterday 10:42 AM


All times are GMT -4. The time now is 11:43 PM.

Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
2013 John Wiley & Sons, Inc.