Sharontha
06-26-2002, 10:43 AM
I have about 20 reports in my database. Rather than me putting 20 buttons, Can i have a combo box where the user can select the report that he/she would like to run? If any of you guys can lead me in the right direction regarding this i would greatly appreciate it....FYI i'm new at access ;)
Thank You.
David R
06-26-2002, 11:09 AM
Now put a combo box with two columns on this form. The first column is what you want to display as the name of your report; say, "Quarterly Financial Report". The second column is the actual name of the report; say, "rptQtrFinance". The second column can actually be width 0" which will make it invisible to the user. (if you have 20 reports and are anticipating having more, I'd strongly recommend putting these combo columns in a small hidden table, so you can add/change it easier)
Now put a button on your form that says "Run Report". Follow the command button wizard to allow you to Open a Report. It doesn't matter what report you let the wizard choose. When it finishes, go into the button and edit the Click event. Look for a line that says: stDocName = "ReportYouSelected"In place of this put the following: If IsNull(Me.comboboxName) Then
MsgBox "You must select a report from the list."
Exit Sub
Else
stDocName = Me.comboboxName.Column(2)
End IfThat should do it. You can put a "Cancel" button on this mini form as well.
Sharontha
06-26-2002, 11:35 AM
Thank Very Much David. Let me try and i'll get back to you if i have any problems.
Sharontha
06-26-2002, 12:48 PM
The below is what i have but it's giving me the following msg ( compile error: Else without if) why is that?
Private Sub Run_Reports_Click()
On Error GoTo Err_Run_Reports_Click
Dim stDocName As String
stDocName = "If IsNull(Me.Combo4) Then"
MsgBox "You must select a report from the list."
Exit Sub
Else
stDocName = Me.Combo4.Column(1)
End If
DoCmd.OpenReport stDocName, acPreview
Exit_Run_Reports_Click:
Exit Sub
Err_Run_Reports_Click:
MsgBox Err.Description
Resume Exit_Run_Reports_Click
End Sub
David R
06-26-2002, 12:58 PM
Try this (my changes underlined for clarity):Private Sub Run_Reports_Click()
On Error GoTo Err_Run_Reports_Click
Dim stDocName As String
If IsNull(Me.Combo4) Then
MsgBox "You must select a report from the list."
Exit Sub
Else
stDocName = Me.Combo4.Column(1)
End If
DoCmd.OpenReport stDocName, acPreview
Exit_Run_Reports_Click:
Exit Sub
Err_Run_Reports_Click:
MsgBox Err.Description
Resume Exit_Run_Reports_Click
End Sub Perhaps I wasn't clear; the first line says "If no report is selected, do nothing."
Sharontha
06-26-2002, 01:52 PM
Eureka!! it worked ! David thanx a lot for your help!!