By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,665 Members | 2,646 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,665 IT Pros & Developers. It's quick & easy.

Using a combo box to open a report

P: 2
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:
Expand|Select|Wrap|Line Numbers
  1. Private Sub ReportCombo_AfterUpdate()
  2.  
  3. DoCmd.OpenReport Me.ReportCombo, acViewPreview
  4.  
  5. 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.
Jan 18 '10 #1

✓ answered by ADezii

  1. In the Open() Event of the Form, populate/define the Combo Box (most basic approach)
    Expand|Select|Wrap|Line Numbers
    1. Private Sub Form_Open(Cancel As Integer)
    2. Dim intNumOfReports As Integer
    3. Dim intRptCounter As Integer
    4. Dim strBuild As String
    5.  
    6. intNumOfReports = CurrentDb.Containers("Reports").Documents.Count
    7.  
    8. Me![cboReports].LimitToList = True
    9.  
    10. If intNumOfReports <> 0 Then
    11.   Me![cboReports].RowSourceType = "Value List"
    12.   Me![cboReports].LimitToList = True
    13.     For intRptCounter = 0 To intNumOfReports - 1
    14.       strBuild = strBuild & CurrentDb.Containers("Reports").Documents(intRptCounter).Name & ","
    15.     Next
    16.       Me![cboReports].RowSource = Left$(strBuild, Len(strBuild) - 1)
    17. End If
    18. End Sub
  2. Open the chosen Report via the AfterUpdate() Event of the Combo Box
    Expand|Select|Wrap|Line Numbers
    1. Private Sub cboReports_AfterUpdate()
    2. If Not IsNull(Me![cboReports]) Then
    3.   DoCmd.OpenReport Me![cboReports], acViewPreview
    4. End If
    5. End Sub

Share this Question
Share on Google+
3 Replies


ADezii
Expert 5K+
P: 8,607
  1. In the Open() Event of the Form, populate/define the Combo Box (most basic approach)
    Expand|Select|Wrap|Line Numbers
    1. Private Sub Form_Open(Cancel As Integer)
    2. Dim intNumOfReports As Integer
    3. Dim intRptCounter As Integer
    4. Dim strBuild As String
    5.  
    6. intNumOfReports = CurrentDb.Containers("Reports").Documents.Count
    7.  
    8. Me![cboReports].LimitToList = True
    9.  
    10. If intNumOfReports <> 0 Then
    11.   Me![cboReports].RowSourceType = "Value List"
    12.   Me![cboReports].LimitToList = True
    13.     For intRptCounter = 0 To intNumOfReports - 1
    14.       strBuild = strBuild & CurrentDb.Containers("Reports").Documents(intRptCounter).Name & ","
    15.     Next
    16.       Me![cboReports].RowSource = Left$(strBuild, Len(strBuild) - 1)
    17. End If
    18. End Sub
  2. Open the chosen Report via the AfterUpdate() Event of the Combo Box
    Expand|Select|Wrap|Line Numbers
    1. Private Sub cboReports_AfterUpdate()
    2. If Not IsNull(Me![cboReports]) Then
    3.   DoCmd.OpenReport Me![cboReports], acViewPreview
    4. End If
    5. End Sub
Jan 18 '10 #2

P: 2
Thanks so much, it is working now :-)
Jan 18 '10 #3

ADezii
Expert 5K+
P: 8,607
You are quite welcome.
Jan 18 '10 #4

Post your reply

Sign in to post your reply or Sign up for a free account.