Is it possible to run reports through a combo box?

Sharontha

Registered User.
Local time
Today, 07:05
Joined
Jun 20, 2002
Messages
14
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.
 
Make a small unbound 'popup' form

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:
Code:
    stDocName = "ReportYouSelected"
In place of this put the following:
Code:
    If IsNull(Me.comboboxName) Then 
       MsgBox "You must select a report from the list."
       Exit Sub
    Else
       stDocName = Me.comboboxName.Column(2)
    End If
That should do it. You can put a "Cancel" button on this mini form as well.
 
Thank Very Much David. Let me try and i'll get back to you if i have any problems.
 
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
 
Try this (my changes underlined for clarity):
Code:
Private Sub Run_Reports_Click()
On Error GoTo Err_Run_Reports_Click

    Dim stDocName As String

    [u]If IsNull(Me.Combo4) Then[/u]
       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."
 
Eureka!! it worked ! David thanx a lot for your help!!
 

Users who are viewing this thread

Back
Top Bottom