OpenReport error handling

S

Stephanie

Hello.
I have a form with parameters, so the user can enter the start date and end
date and then click on Preview to run the report. The form has a Preview
error handling code. If the form is closed without clicking preview, the form
shuts nicely.

However, I have this report set to run from an Option button on a
switchboard form, that in itself has a Preview button: I click the option
button, then click on the switchboard Preview button, the parameter form
opens (where I could enter the parameter dates and click Preview to run the
report- but here I don't), I close the parameter form without entering
anything and get: "Error in procedure cmdPreview_Click, Error 2501: The
OpenReport action was canceled."

I thought I had trapped this error.
This is the error handling I have on the switchboard:

Private Sub cmdPreview_Click()
On Error GoTo ProcError

DoCmd.OpenReport Report_Name, acPreview

ExitProc:
Exit Sub
ProcError:
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "Error in procedure cmdPreview_Click..."
Resume ExitProc

End Sub

Private Sub Report_Error(DataErr As Integer, Response As Integer)
PrintPreport_Error:
If Err.Number <> 2501 Then
GoTo ProcError
End If

ExitProc:
Exit Sub
ProcError:
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "Error in procedure Report_Error..."
Resume ExitProc

End Sub

Private Sub Report_NoData(Cancel As Integer)
On Error GoTo ProcError

MsgBox "No data meets the report criteria.", vbInformation + vbOKOnly,
"Animals Deceased"
Cancel = True

ExitProc:
Exit Sub
ProcError:
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "Error in procedure Report_NoData..."
Resume ExitProc

End Sub

Obviously, I don't have it quite right. I'd appreciate your help in trapping
the dreaded 2501.
Thanks!
 
M

Matthias Klaey

Stephanie said:
Hello.
I have a form with parameters, so the user can enter the start date and end
date and then click on Preview to run the report. The form has a Preview
error handling code. If the form is closed without clicking preview, the form
shuts nicely.

However, I have this report set to run from an Option button on a
switchboard form, that in itself has a Preview button: I click the option
button, then click on the switchboard Preview button, the parameter form
opens (where I could enter the parameter dates and click Preview to run the
report- but here I don't), I close the parameter form without entering
anything and get: "Error in procedure cmdPreview_Click, Error 2501: The
OpenReport action was canceled."

I thought I had trapped this error.
This is the error handling I have on the switchboard:

Private Sub cmdPreview_Click()
On Error GoTo ProcError

DoCmd.OpenReport Report_Name, acPreview

ExitProc:
Exit Sub
ProcError:
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "Error in procedure cmdPreview_Click..."
Resume ExitProc

End Sub
[...]


Obviously, I don't have it quite right. I'd appreciate your help in trapping
the dreaded 2501.
Thanks!

I think you need to handle the 2501 error as follows:

Dim lngErr As Long

On Error Resume Next
DoCmd.OpenReport Report_Name, acPreview
lngErr = Err.Number
On Error GoTo ProcError
If (lngErr <> 0) And (lngErr <> 2501) Then
Err.Raise lngErr ' Or, as an alternative: GoTo ProcError
End If

You don't need the Report_Error event.

HTH
Matthias Kläy
 
S

Stephanie

Perfect! Thanks for the help!

Matthias Klaey said:
Stephanie said:
Hello.
I have a form with parameters, so the user can enter the start date and end
date and then click on Preview to run the report. The form has a Preview
error handling code. If the form is closed without clicking preview, the form
shuts nicely.

However, I have this report set to run from an Option button on a
switchboard form, that in itself has a Preview button: I click the option
button, then click on the switchboard Preview button, the parameter form
opens (where I could enter the parameter dates and click Preview to run the
report- but here I don't), I close the parameter form without entering
anything and get: "Error in procedure cmdPreview_Click, Error 2501: The
OpenReport action was canceled."

I thought I had trapped this error.
This is the error handling I have on the switchboard:

Private Sub cmdPreview_Click()
On Error GoTo ProcError

DoCmd.OpenReport Report_Name, acPreview

ExitProc:
Exit Sub
ProcError:
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "Error in procedure cmdPreview_Click..."
Resume ExitProc

End Sub
[...]


Obviously, I don't have it quite right. I'd appreciate your help in trapping
the dreaded 2501.
Thanks!

I think you need to handle the 2501 error as follows:

Dim lngErr As Long

On Error Resume Next
DoCmd.OpenReport Report_Name, acPreview
lngErr = Err.Number
On Error GoTo ProcError
If (lngErr <> 0) And (lngErr <> 2501) Then
Err.Raise lngErr ' Or, as an alternative: GoTo ProcError
End If

You don't need the Report_Error event.

HTH
Matthias Kläy
 

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