Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2010
    Posts
    9

    Unanswered: Run Access report from ListBox selection.

    Hi there, I have a listbox with the names of reports that someone can run just by selecting on or two of the report names that appears within the list that comes from TABLE_REPORT_NAMES. With the following code, I am able to run this code and populate a secondary table (TEMP_TABLE_REPORTS ) with the selections that have been made. Now I need to be able to run the report that has been selected and am totally lost. Hopefully someone can help me with this.



    Private Sub BTN_RUN_REPORTS_Click()
    Dim rs As New ADODB.Recordset
    Dim cnn As New ADODB.Connection
    Dim strSQL As String

    DoCmd.SetWarnings False
    DoCmd****nSQL "DELETE TEMP_TABLE_REPORTS.* FROM TEMP_TABLE_REPORTS;"
    DoCmd.SetWarnings True

    Set cnn = CurrentProject.Connection
    strSQL = "SELECT * From TEMP_TABLE_REPORTS"

    rs.Open strSQL, cnn, adOpenDynamic, adLockOptimistic

    'Ensure that primary key is the bound value of the listbox
    Dim VarItem As Variant
    Dim VarData As Variant
    For Each VarItem In Me.LIST_REPORTS.ItemsSelected
    VarData = Me.LIST_REPORTS.ItemData(VarItem)

    rs.AddNew
    rs.Fields("REPORT_NAME") = VarData
    rs.Update
    Next VarItem

    'Retrieve report names from table selected by end-user
    DoCmd.OpenQuery ("Q_TEMP_TABLE_REPORTS")

    End Sub

  2. #2
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    I wouldn't bother with the temp table. I'd do this inside the loop:

    DoCmd.OpenReport Me.LIST_REPORTS.ItemData(VarItem), acViewPreview
    Paul

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •