Run Different Reports with Same Button

A

Angelsnecropolis

I have a combo box named "ReportList" and a button named "GenerateReport" on
a form. I'm trying to make the report selected in the combo box run when the
one button is pressed as opposed to making several buttons for each report.

I'm using the code below for a button for each report:

Private Sub GenerateReport_Click()
On Error GoTo Err_GenerateReport_Click

Dim stDocName As String

stDocName = "Takeovers - Kevin"
DoCmd.OpenReport stDocName, acPreview

Exit_GenerateReport_Click:
Exit Sub

Err_GenerateReport_Click:
MsgBox Err.Description
Resume Exit_GenerateReport_Click

End Sub


Thanks!
 
D

Douglas J. Steele

Private Sub GenerateReport_Click()
On Error GoTo Err_GenerateReport_Click

If IsNull(Me!ReportList Then
MsgBox "You must select a report first."
Else
DoCmd.OpenReport Me!ReportList, acPreview
End If

Exit_GenerateReport_Click:
Exit Sub

Err_GenerateReport_Click:
MsgBox Err.Description
Resume Exit_GenerateReport_Click

End Sub
 
F

fredg

I have a combo box named "ReportList" and a button named "GenerateReport" on
a form. I'm trying to make the report selected in the combo box run when the
one button is pressed as opposed to making several buttons for each report.

I'm using the code below for a button for each report:
Private Sub GenerateReport_Click()
On Error GoTo Err_GenerateReport_Click

If Not IsNull(Me![ReportList]) Then
DoCmd.OpenReport Me![ReportList], acPreview
End If

Exit_GenerateReport_Click:
Exit Sub

Err_GenerateReport_Click:
MsgBox Err.Description
Resume Exit_GenerateReport_Click

End Sub

Why use a command button?
Why not simply code the ReportList AfterUpdate event:

DoCmd.OpenReport Me.[ReportList], acPreview
 
D

Douglas J. Steele

Ooops. Left off a closing parenthesis:

Private Sub GenerateReport_Click()
On Error GoTo Err_GenerateReport_Click

If IsNull(Me!ReportList) Then
MsgBox "You must select a report first."
Else
DoCmd.OpenReport Me!ReportList, acPreview
End If

Exit_GenerateReport_Click:
Exit Sub

Err_GenerateReport_Click:
MsgBox Err.Description
Resume Exit_GenerateReport_Click

End Sub
 
A

Angelsnecropolis

Works Beautifully! Thanks! You're awesome!

Douglas J. Steele said:
Ooops. Left off a closing parenthesis:

Private Sub GenerateReport_Click()
On Error GoTo Err_GenerateReport_Click

If IsNull(Me!ReportList) Then
MsgBox "You must select a report first."
Else
DoCmd.OpenReport Me!ReportList, acPreview
End If

Exit_GenerateReport_Click:
Exit Sub

Err_GenerateReport_Click:
MsgBox Err.Description
Resume Exit_GenerateReport_Click

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top