Cancelling a report

L

Leslie Isaacs

Hello All

I am using A97.

I have a button on a form that, when clicked, brings up two reports. The
on-event code is below. The problem is that I want to stop the error massage
that appears when either report has no data. Both reports have the 'on no
data' event set to Cancel = True, but how do I trap the error. Usually 'If
Err = 2501 Then Err.Clear'
works, but with two reports it doesn't!

Hope someone can help.

Many thanks
Leslie Iaacs

My code:

Private Sub Command674_Click()
On Error GoTo Err_Command674_Click

Dim stDocName As String

stDocName = "rpt P14 try 2004/05"
DoCmd.OpenReport stDocName, acPreview

stDocName = "rpt P14 try dcmonths 2004/05"
DoCmd.OpenReport stDocName, acPreview

If Err = 2501 Then Err.Clear

Exit_Command674_Click:
Exit Sub

Err_Command674_Click:
MsgBox Err.Description
Resume Exit_Command674_Click
End Sub
 
J

Jeff Conrad

in message:
Hello All

I am using A97.

I have a button on a form that, when clicked, brings up two reports. The
on-event code is below. The problem is that I want to stop the error massage
that appears when either report has no data. Both reports have the 'on no
data' event set to Cancel = True, but how do I trap the error. Usually 'If
Err = 2501 Then Err.Clear'
works, but with two reports it doesn't!

Hope someone can help.

Many thanks
Leslie Iaacs

My code:

How about:

Private Sub Command674_Click()
On Error GoTo Err_Command674_Click

Dim stDocName As String

stDocName = "rpt P14 try 2004/05"
DoCmd.OpenReport stDocName, acPreview

stDocName = "rpt P14 try dcmonths 2004/05"
DoCmd.OpenReport stDocName, acPreview

Exit_Command674_Click:
Exit Sub

Err_Command674_Click:
If Err.Number = 2501 Then
Resume Next
Else
MsgBox Err.Description
End If
Resume Exit_Command674_Click

End Sub
 
S

SA

Leslie:

The err.clear code won't have any impact in your code because the error is
raised before that line is run and the process is routed to the error
handler. To fix this, simply add a line to your error handler, either

If err.number = 2501 Then resume next

or

If err.number = 2501 then goto Exit Command674_Click:

(Geeze to have 674 controls on a form or report is pretty huge)
 

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