Hi.
The problem I have is how to handle things if either of the reports has no
data.
Create a public subroutine in a module that opens the one report passed to
it. Your button's OnClick( ) event will call this subroutine once for each
report. That way, if one report is cancelled, it's the only report being
handled by that subroutine's error handler.
In the form with the button that opens the two reports, try:
' * * * * Start Code * * * *
Private Sub Open2RptsBtn_Click()
On Error GoTo ErrHandler
Call OpenRpt("rptMyReport")
Call OpenRpt("rptMyOtherReport")
Exit Sub
ErrHandler:
MsgBox "Error in Open2RptsBtn_Click( ) in " & vbCrLf & _
Me.Name & " form." & vbCrLf & vbCrLf & _
"Error #" & Err.Number & vbCrLf & Err.Description
Err.Clear
End Sub
' * * * * End Code * * * *
Paste the following code in a module:
' * * * * Start Code * * * *
Public Sub OpenRpt(sRptName As String)
On Error GoTo ErrHandler
DoCmd.OpenReport sRptName, acViewPreview
Exit Sub
ErrHandler:
If (Err.Number <> 2501) Then ' Report not cancelled.
MsgBox "Error in OpenRpts( )." & vbCrLf & vbCrLf & _
"Error #" & Err.Number & vbCrLf & Err.Description
End If
Err.Clear
End Sub
' * * * * End Code * * * *
HTH.
Gunny
See
http://www.QBuilt.com for all your database needs.
See
http://www.Access.QBuilt.com for Microsoft Access tips.
(Please remove ZERO_SPAM from my reply E-mail address, so that a message
will be forwarded to me.)
Beware to those who use munged addresses: known newsgroup E-mail harvesters
for spammers are (e-mail address removed) and (e-mail address removed)
- - -
When you see correct answers to your question posted in Microsoft's Online
Community, please sign in to the Community and mark these posts as "Answers,"
so that all may benefit by filtering on "Answered questions" and quickly
finding the right answers to similar questions. Remember that questions
answered the quickest are often from those who have a history of rewarding
the contributors who have taken the time to answer questions correctly.