No data event

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How do I suppress the 'OpenReport action was canceled' message when I set the
cancel = true in the NoData event.
 
You need an error handler in the code that opened the report. The error
number you're looking for is 2501.

Example:
Private Sub cmdMyButton_Click()
On Error GoTo CheckError
DoCmd.OpenReport "rptMyReport, acViewPreview
ExitHere:
Exit Sub
CheckError:
If Err.Number = 2501 Then Resume ExitHere
MsgBox "Error # " & Err.Number & vbCrLf & Err.Description, vbOkOnly +
vbCritical, "Error in cmbMyButton_Click"
End Sub
 
Thank you!!!

Wayne Morgan said:
You need an error handler in the code that opened the report. The error
number you're looking for is 2501.

Example:
Private Sub cmdMyButton_Click()
On Error GoTo CheckError
DoCmd.OpenReport "rptMyReport, acViewPreview
ExitHere:
Exit Sub
CheckError:
If Err.Number = 2501 Then Resume ExitHere
MsgBox "Error # " & Err.Number & vbCrLf & Err.Description, vbOkOnly +
vbCritical, "Error in cmbMyButton_Click"
End Sub
 
Wayne said:
You need an error handler in the code that opened the report. The
error number you're looking for is 2501.

Example:
Private Sub cmdMyButton_Click()
On Error GoTo CheckError
DoCmd.OpenReport "rptMyReport, acViewPreview
ExitHere:
Exit Sub
CheckError:
If Err.Number = 2501 Then Resume ExitHere
MsgBox "Error # " & Err.Number & vbCrLf & Err.Description, vbOkOnly +
vbCritical, "Error in cmbMyButton_Click"
End Sub

What I did a while back was create two custom functions. One for opening
Forms and one for Reports. They take the exact arguments and syntax as
DoCmd.Open... but automatically handle error 2501.

The hardest part is remembering to use them instead of the built in methods.
 
Back
Top