Results 1 to 5 of 5

Run-time error 3011 on TransferSpreadsheet acImport

  1. #1
    Sephaerius is offline Advanced Beginner
    Windows 7 64bit Access 2013 64bit
    Join Date
    Aug 2013
    Posts
    40

    Run-time error 3011 on TransferSpreadsheet acImport

    I'm getting a puzzling error on a function that I've been using for years to import multiple Excel worksheets into a table. This is working code that is actively in use to import other workbooks with multiple worksheets, however I'm working with a new workbook for this specific capture, and it's not cooperating.
    As you can see from the below code, I'm grabbing a workbook and trying to import the 4 sheets by name (as I understand is the only way.) I assure you that the names of the sheets are correct, yet the error (3011 - The MS Access database engine could not find the object) states that it cannot find it. When I take the names off, it grabs Sheet1 by default and nothing else. What could be going on that's preventing it from recognizing the named sheets? What else can I try? Thanks!



    Code:
    Public Function import_lex_star_3m()
        Dim fDialog As Office.FileDialog
        Dim varFile As Variant
        Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
        With fDialog
           .AllowMultiSelect = True
           .Title = "Please select STAR files"
           .InitialFileName = Environ("USERPROFILE") & "\Desktop\DNFB Holds Report\Reports\" & "LEXINGTON*STAR*" & ".xlsx"
           .Filters.Clear
           .Filters.Add "Excel File", "*.xls*"
           If .Show = True Then
              For Each varFile In .SelectedItems
                 DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel12, "lex_star_3m_detail", varFile, True, "CCK"
                 DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel12, "lex_star_3m_detail", varFile, True, "ST JOSEPH MAIN"
                 DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel12, "lex_star_3m_detail", varFile, True, "ST JOSEPH EAST"
                 DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel12, "lex_star_3m_detail", varFile, True, "JESSAMINE"
                Next
           End If
        End With
    End Function

  2. #2
    ranman256's Avatar
    ranman256 is online now VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    6,557
    does varFile have the FULL path name?

  3. #3
    Sephaerius is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Aug 2013
    Posts
    40
    Quote Originally Posted by ranman256 View Post
    does varFile have the FULL path name?
    Yes, the path and file name are passed here:

    Code:
    .InitialFileName = Environ("USERPROFILE") & "\Desktop\DNFB Holds Report\Reports\" & "LEXINGTON*STAR*" & ".xlsx"
    It grabs the file, no problem. And it will import data from Sheet1 if I do not define the sheet names. But that's the issue, I have 4 sheets in that workbook that need to be imported. The error is saying it cannot find the sheet name and I don't know why.

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    44,363
    Put ! character at end of sheet name. Worked for me.
    To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression. Attachment Manager is below Advanced editor window, click Go Advanced below Quick Reply window.

  5. #5
    Sephaerius is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Aug 2013
    Posts
    40
    Quote Originally Posted by June7 View Post
    Put ! character at end of sheet name. Worked for me.
    Haha! That DOES work! Excellent! Thank you!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 12
    Last Post: 05-31-2016, 01:12 PM
  2. Replies: 10
    Last Post: 02-18-2016, 08:44 PM
  3. Replies: 3
    Last Post: 07-29-2014, 12:01 PM
  4. Replies: 8
    Last Post: 07-02-2014, 09:58 AM
  5. Replies: 0
    Last Post: 01-18-2006, 07:02 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Tech Forums: Microsoft Office Forums