Results 1 to 7 of 7
  1. #1
    captdkl02 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Dec 2012
    Posts
    33

    Question Runtime error 3011 VBA export access report to excell

    Hello,



    I using excel 2010 and access 2010. I have VBA script runtime error 3011 when running script. It has problem finding access report. First I was passing in as variable with the name. Then I used a script to pull in the report name from access and it is still failing with same error.

    Code is shown below.

    Any help greatly appreciated.

    Thank you.

    David

    -----------

    Private Sub Command29_Click()
    Dim reportname As String
    Dim theFilePath As String, FilePath As String, tempStr As String

    ' reportname = Me.My_DBTableName I was passing in here, but comment the code out

    tempStr = Application.CurrentDb.Containers("Reports").Docume nts(2).Name ' using command pulling in the report name from Access database

    reportname = tempStr
    theFilePath = Me.My_Export_file_path
    theFilePath = theFilePath & reportname & ".xlsx"

    ' It is failing with code in red
    DoCmd.OutputTo acOutputQuery, reportname, acFormatXLSX, theFilePath, True

    ' I was using the transferspreadsheet command and it was failing for the same reason of not finding report name

    ' DoCmd.TransferSpreadsheet acExport, 10, reportname, theFilePath, True

    MsgBox "Look on your desktop for the report."

    End Sub

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Use acOutputReport instead of acOutputQuery.

    Be aware, reports don't output very nice.

    Step debug - is the reportname variable getting correct value?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    tanvi is offline Competent Performer
    Windows XP Access 2010 32bit
    Join Date
    Mar 2012
    Posts
    100
    As per my knowledge, this error occurs when an object can't be found. The error should tell you what object it can't find. First make sure that the object is exist or not and also check that you are correctly spell its name & pathname.

  4. #4
    captdkl02 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Dec 2012
    Posts
    33
    It is passing the name of the report that I was expecting. I changed the code slightly using DoCmd.OutputTo acOutputReport. I have included the code again with slight modifications. It is writing the file to the directory, however; I am receiving another errror. Error message => "Excel cannot open the file 'test.xlsx' because the file format or extension is not valid. Verify that the file has not been corrupted and that the file extension matches the format of the file."

    Private Sub Command29_Click()
    Dim reportname As String
    Dim theFilePath As String, FilePath As String, tempStr As String

    ' reportname = Me.My_DBTableName
    tempStr = Application.CurrentDb.Containers("Reports").Docume nts(2).Name

    reportname = tempStr
    theFilePath = Me.My_Export_file_path
    theFilePath = theFilePath & reportname & ".xlsx"

    ' outReportData = "your report name"
    DoCmd.OutputTo acOutputReport, reportname, acFormatXLS, theFilePath, -1

    'Keep Excel file closed = 0; to open Excel file automatically = -1

    ' DoCmd.OutputTo acOutputQuery, reportname, acFormatXLSX, theFilePath, True

    ' DoCmd.TransferSpreadsheet acExport, 10, reportname, theFilePath, True
    MsgBox "Look at the file directory you specified for the report."
    End Sub

  5. #5
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    You show xlsx in file path but only xls in the format argument.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    tanvi is offline Competent Performer
    Windows XP Access 2010 32bit
    Join Date
    Mar 2012
    Posts
    100
    Thiserror (Excelcannot open the file 'test.xlsx')only occurs when the file is not compatible with Excel or the file got corrupted. Please visit this article for solution:http://file-repair.blogspot.in/2012/09/how-to-fix-error-excel-cannot-open-file.html

  7. #7
    captdkl02 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Dec 2012
    Posts
    33
    Thank you for your responses. I was able to get the code to work. The report output to excel still lost the formatting I was looking for. Anyway, I believe will have to export access into excel 1st and then format the excel file 2nd.

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

Similar Threads

  1. Replies: 7
    Last Post: 12-10-2018, 05:24 PM
  2. Runtime Error 3075 - Access 2010
    By cwturner2 in forum Programming
    Replies: 5
    Last Post: 06-29-2012, 04:03 PM
  3. Replies: 13
    Last Post: 06-12-2012, 09:52 PM
  4. Replies: 3
    Last Post: 05-30-2012, 01:43 PM
  5. Access 2003 R6025 runtime error
    By TylerTexas in forum Access
    Replies: 0
    Last Post: 12-05-2011, 03:14 PM

Posting Permissions

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