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

opening reports with a selection with a combo box

P: 3
I have used some code which I found on your site showing how to open reports with a combobox. It works ok.
But the comb box shows all reports. I have some reports;"aged debtors- March,aged debtors-april. I onl ywant the combo box to show these reports. How can I get the comb box to only show some reports and not all.

The code for the combo box is:
Private Sub cboReports_AfterUpdate()
If Not IsNull(Me![cboReports]) Then
DoCmd.OpenReport Me![cboReports], acViewPreview
End If
End Sub

The code for the form is;
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(intRptCo unter).Name & ","
Next
Me![cboReports].RowSource = Left$(strBuild, Len(strBuild) - 1)
End If

End Sub

This is the cdoe given to a reply on your site. Any help would be appreciated

KP
Mar 10 '10 #1
Share this Question
Share on Google+
1 Reply


TheSmileyCoder
Expert Mod 100+
P: 2,321
Please remember to use the [code][/code] tags around your code, as it makes it much easier to read.

The code you copied for the Form_Open simply takes all the reports in the database.
This code is modified, to a few specific reports, named rep_MyFirstReport, rep_MySecondReport and so on. You can then replace those names with the names of your reports.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Open(Cancel As Integer)
  2.  
  3. 'Make the valuelist String
  4.    Dim strBuild As String
  5.    strBuild="rep_MyFirstReport," & _
  6.                 "rep_MySecondReport," & _
  7.                 "rep_MyLastReport"
  8.  
  9. 'Set the combobox
  10.    Me![cboReports].LimitToList = True
  11.    Me![cboReports].RowSourceType = "Value List"
  12.    Me![cboReports].RowSource = strBuild
  13. End Sub
Mar 10 '10 #2

Post your reply

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