gdunn59
asked on
No Data on Report . . . Still get error about Report Was Canceled . . . Need to Suppress
I have a button that runs a report, and I have code in the NoData Event of the Report (see below), but I still get the message that the Report was canceled. How do I suppress this?
Code on the NoData Event of the Report:
Code for Button:
Thanks,
gdunn59
Code on the NoData Event of the Report:
MsgBox "No Data Found For This Employee", vbExclamation, "No Data"
Cancel = True
End Sub
Code for Button:
Private Sub cmdAssocRpt_Click()
On Error GoTo Err_cmdAssocRpt_Click
Dim stDocName As String
DoCmd.SetWarnings False
If IsNull(Me.cboReportCateg) Or IsNull(Me.cboCategSelect) Then
MsgBox "Please make selections from the drop-downs for a Auditor, Department, Employee or Manager", vbOKOnly
Me.cboReportCateg.SetFocus
Me.cboReportCateg.Dropdown
ElseIf Me.cboReportCateg = "Employee" Then
stDocName = "rptAssociate_Report"
DoCmd.OpenReport stDocName, acPreview
End If
Exit_cmdAssocRpt_Click:
Exit Sub
Err_cmdAssocRpt_Click:
If Err.Number = 2501 Then
'no action required - ignore the error - because opening of report was cancelled
Else
MsgBox Err.Description
End If
DoCmd.GoToControl "cboCategSelect"
Me.cboCategSelect = Null
Me.cboReportCateg = Null
Me.txtBeginDT = Null
Me.txtEndDT = Null
Me.cboDept = Null
GoTo Exit_cmdAssocRpt_Click
DoCmd.SetWarnings True
End Sub
Thanks,
gdunn59
ASKER
Yes 2501 is the error I'm getting.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Here is the exact error message I am getting:
Run-time error '2501':
The OpenReport action was canceled.
Run-time error '2501':
The OpenReport action was canceled.
ASKER
It had "Break on All Errors" selected. is that okay or do I need to select the option you mentioned above "Break on unhandled errors"?
"It had "Break on All Errors" selected"
That is your problem ... set to Unhanded Errors
That is your problem ... set to Unhanded Errors
ASKER
Ok. That worked.
Thanks,
gdunn59
Thanks,
gdunn59
That would do it. Break on all errors should only be used to debug your code
I think mbizup noted this first, or at least implied it. Actually, I didn't even see that post.
Be *SURE* to get rid of DoCmd.SetWarnings ...
mx
Be *SURE* to get rid of DoCmd.SetWarnings ...
mx
Thanks, mx
I see you are already trapping for error 2501, which normally would work. Is that the error you are getting? Occasionally, I've seen a slightly different error in this scenario.
mx