Results 1 to 4 of 4
  1. #1
    memcha is offline Novice
    Windows XP Access 2007
    Join Date
    Dec 2013
    Posts
    2

    Post How to export to excell a report from a list control.


    I have a problem with my command to export a report in to excell, I create a form with a list control that populates all my reports, I am able to preview the report or sent it to print when I choose one. but now I would like to create a command that can send the desire report to excell.

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    My preffered method for exporting data to excel is the "DoCmd.TransferSpreadsheet" method. I am not sure how your report and listbox come into play but here is an example of some code that uses a Saved Query Object and a string variable to define the file path to use.

    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, strQDF, strDirectory, True

  3. #3
    memcha is offline Novice
    Windows XP Access 2007
    Join Date
    Dec 2013
    Posts
    2
    this is what I have on my command to open any report from my list. I have not touch Access for long time I am starting to do it but it getting harder to recall everithing.


    Private Sub cmdOpenReport_Click()
    On Error GoTo cmdOpenReport_ClickErr
    If Not IsNull(Me.lstReports) Then
    DoCmd.OpenReport Me.lstReports, IIf(Me.ChkPreview.Value, acViewPreview, acViewNormal)
    End If
    Exit Sub
    cmdOpenReport_ClickErr:
    Select Case Err.Number
    Case 2501 ' Cancelled by user, or by NoData event.
    MsgBox "Report cancelled, or no matching data.", vbInformation, "Information"
    Case Else
    MsgBox "Error " & Err & ": " & Error$, vbInformation, "cmdOpenReport_Click()"
    End Select
    Resume Next
    End Sub

    and this is what I have to populate the reports list . all everything are on a FORM

    Function EnumReports(fld As Control, id As Variant, row As Variant, col As Variant, code As Variant) As Variant
    ' Purpose: Supplies the name of all saved reports to a list box.
    ' Dim db As Database, dox As Documents, i As Integer
    Static sRptName(255) As String ' Array to store report names.
    Static iRptCount As Integer ' Number of saved reports.
    ' Respond to the supplied value of "code".
    Select Case code
    Case acLBInitialize ' Called once when form opens.
    Set db = CurrentDb()
    Set dox = db.Containers!Reports.Documents
    iRptCount = dox.Count ' Remember number of reports.
    For i = 0 To iRptCount - 1
    sRptName(i) = dox(i).Name ' Load report names into array.
    Next
    EnumReports = True
    Case acLBOpen
    EnumReports = Timer ' Return a unique identifier.
    Case acLBGetRowCount ' Number of rows
    EnumReports = iRptCount
    Case acLBGetColumnCount ' 1 column
    EnumReports = 1
    Case acLBGetColumnWidth ' 2 inches
    EnumReports = 2 * 1440
    Case acLBGetValue ' The report name from the array.
    EnumReports = sRptName(row)
    Case acLBEnd
    Erase sRptName ' Deallocate array.
    iRptCount = 0
    End Select
    End Function


    Click image for larger version. 

Name:	form.JPG 
Views:	13 
Size:	36.6 KB 
ID:	14892

    and My problem is with command5 I would like to grab the selected report and exported to excell.

    thank you for answer and your help.

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    This is how I have done it in the past. I had to look at some old code. Nowadays things are moving to Macros and the OutputTo method's days may be limited. If you have Office Objects referenced this should work.

    Code:
    DoCmd.OpenReport , acViewPreview, , strWhereCondition, acHidden
    DoCmd.SelectObject acReport, "ReportName"
    DoCmd.OutputTo acOutputReport, "ReportName", acSpreadsheetTypeExcel9, strPath
    DoCmd.Close acReport, "ReportName"

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

Similar Threads

  1. How to control Date format in Mailmerge export
    By beginner33 in forum Import/Export Data
    Replies: 4
    Last Post: 10-02-2014, 01:41 AM
  2. Replies: 6
    Last Post: 12-21-2012, 02:21 PM
  3. import/export attachments to SharePoint list
    By Cojack in forum Import/Export Data
    Replies: 0
    Last Post: 07-15-2011, 01:39 AM
  4. Image List Control
    By Fredwards in forum Access
    Replies: 2
    Last Post: 11-23-2010, 10:30 PM
  5. export Excel control row count
    By TheShabz in forum Code Repository
    Replies: 1
    Last Post: 04-17-2010, 12:00 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
  •  
Other Forums: Microsoft Office Forums