Run Different Reports with Same Button

  • Thread starter Thread starter Angelsnecropolis
  • Start date Start date
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!
 
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
 
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
 
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
 
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
 
Back
Top