Link to home
Start Free TrialLog in
Avatar of gdunn59
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:
MsgBox "No Data Found For This Employee", vbExclamation, "No Data"
  Cancel = True
End Sub

Open in new window



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

Open in new window


Thanks,
gdunn59
Avatar of DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
Flag of United States of America image

First ... get rid of the DoCmd.SetWarnings  False - very dangerous. And the way you have it, if no error occurs, it never gets set back to True.  You should not need this here.

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
Avatar of gdunn59
gdunn59

ASKER

Yes 2501 is the error I'm getting.
ASKER CERTIFIED SOLUTION
Avatar of mbizup
mbizup
Flag of Kazakhstan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gdunn59

ASKER

Here is the exact error message I am getting:

  Run-time error '2501':

  The OpenReport action was canceled.
Avatar of gdunn59

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
Avatar of gdunn59

ASKER

Ok.  That worked.

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
Thanks, mx