Using a combo box to open a report

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MDay
    New Member
    • Jan 2010
    • 2

    Using a combo box to open a report

    Good morning,

    I would like to use an unbound combo box on a form to preview the selected report. The combo box is populated by a list of all the report names.

    I am currently using the AfterUpdate function to select the report name and am using the the following code:
    Code:
    Private Sub ReportCombo_AfterUpdate()
    
    DoCmd.OpenReport Me.ReportCombo, acViewPreview
    
    End Sub
    When I try to select one of the reports in the list, nothing is happening. How can I get this to work properly?

    Thanks for your help.
    Last edited by NeoPa; Jan 18 '10, 11:09 PM. Reason: Please use the [CODE] tags provided
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    1. In the Open() Event of the Form, populate/define the Combo Box (most basic approach)
      Code:
      Private Sub Form_Open(Cancel As Integer)
      Dim intNumOfReports As Integer
      Dim intRptCounter As Integer
      Dim strBuild As String
      
      intNumOfReports = CurrentDb.Containers("Reports").Documents.Count
      
      Me![cboReports].LimitToList = True
      
      If intNumOfReports <> 0 Then
        Me![cboReports].RowSourceType = "Value List"
        Me![cboReports].LimitToList = True
          For intRptCounter = 0 To intNumOfReports - 1
            strBuild = strBuild & CurrentDb.Containers("Reports").Documents(intRptCounter).Name & ","
          Next
            Me![cboReports].RowSource = Left$(strBuild, Len(strBuild) - 1)
      End If
      End Sub
    2. Open the chosen Report via the AfterUpdate() Event of the Combo Box
      Code:
      Private Sub cboReports_AfterUpdate()
      If Not IsNull(Me![cboReports]) Then
        DoCmd.OpenReport Me![cboReports], acViewPreview
      End If
      End Sub

    Comment

    • MDay
      New Member
      • Jan 2010
      • 2

      #3
      Thanks so much, it is working now :-)

      Comment

      • ADezii
        Recognized Expert Expert
        • Apr 2006
        • 8834

        #4
        You are quite welcome.

        Comment

        Working...