Results 1 to 3 of 3
  1. #1
    Paul H's Avatar
    Paul H is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Sep 2011
    Location
    Richmond, VA
    Posts
    591

    Export Recordsource

    I have a form "frmReports" that opens a list of reports in a table. This works great. I want to give the open of exporting the data behind the report to excel. I'm having trouble nabbing this (the record source). I've gone at this several different ways, but keep stubbing my toe here.



    Code:
    'Opens the selected report in the default report view
    Dim objReport As Report
     
    If Me.cboReports = 0 Then Exit Sub
     
    strReportName = Me.cboReports.Column(1)
    intRptView = Me.cboReports.Column(2)
    strRptName = Me.cboReports.Column(3)
     
    strFileName = CurrentProject.Path & "\Excel\" & strReportName & ".xlsx"
    Set objReport = "Report_" & strRptName
    strRecordSource = objReport.RecordSource
     
    If Me.chkExport = 0 Then
    DoCmd.OpenReport strRptName, intRptView
    Else
    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, strRecordSource, strFileName
    End If
    I keep getting runtime error 424, Object required at Line 11.

    I could just pop the queries in my table and reference them in my code, but some of these reports have embedded SQL.

    Your help would be appreciated.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,597
    Think either of these would work:
    Set objReport = strRptName
    or
    Set objReport = Reports(strRptName)
    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
    Paul H's Avatar
    Paul H is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Sep 2011
    Location
    Richmond, VA
    Posts
    591

    Smile

    Runtime Error 2453 Report name is either misspelled, not open or doesn't exist.

    or I get a type mismatch

    My curiosity is waning. I'm not sure it can be done this way, but here what I did do.

    I listed my queries in the table. Where I had no query, I open the report and grab the record source there, then I call the same function, passing the same arguments from either side. This works. It is not as elegant as I would like, but it still passes muster. Here's my function.

    Code:
    Public Function ExportQuery(strRecordSource, strReportName)
     
    strFileName = CurrentProject.Path & "\Excel\" & strReportName & Format(Date, "_yyyymmdd") & ".xls"
     
    CurrentDb.QueryDefs("qryExportReport").SQL = strRecordSource 
     
    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "qryExportReport", strFileName
     
    MsgBox "This report has been exported to " & vbNewLine & vbNewLine & strFileName
     
    End Function
    Thank you though.

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

Similar Threads

  1. Replies: 3
    Last Post: 08-28-2011, 08:24 PM
  2. Setting Recordsource for Subforms
    By P5C768 in forum Forms
    Replies: 5
    Last Post: 11-16-2010, 05:01 AM
  3. RecordSource help
    By mann2x in forum Access
    Replies: 3
    Last Post: 10-05-2010, 06:44 PM
  4. Replies: 2
    Last Post: 10-16-2009, 02:47 PM
  5. Recordsource with Multiple queries
    By darshita in forum Programming
    Replies: 1
    Last Post: 08-10-2009, 03:17 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