Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to prevent display of "The OpenReport action was canceled" message 4

Status
Not open for further replies.

dabits

Programmer
Apr 28, 2000
18
US
Very strange:)

I am having no luck in surpressing "The OpenReport action was canceled" message when a report finds no data to display! I put code in the NoData event to display a user message and then cancel the event. Like this:

Private Sub Report_NoData(Cancel As Integer)
DoCmd.SetWarnings False
MsgBox "No data found for selected options! Closing report."
Cancel = True

End Sub
Just to be carefule:) I set DoCmd.SetWarnings True on the report close event. I thought the DoCmd.SetWarnings would prevent the "action canceled" message but it doesn't? I even tried putting the DoCmd line on the line right before the DoCmd.OpenReport line in form which run the report. Still no luck. Any ideas on this? BTW, this is Access 97.

Thanks - Dabits
 
Add this before or after the MsgBox:

DoCmd.CancelEvent

It will cancel the no data event and prevent the error altogether.
 
You may want to show the "No Data" message box. So leave the OnNoData as you have it and in the button that opens the report handle the Error you want to suppress.

On Error goto Err_cmdPrint_Click

Const conUserCancelledPrint = 2501

**Your code to run report, etc goes here**

Exit_cmdPrint_Click:
Exit sub

Err_cmdPrint_Click:
If Err <> conUserCancelledPrint then
msgbox err.description
End if
resume Exit_cmdPrint_Click





 
I've tried this code in my event and it doesn't seem to be working. I'm still getting the same error message. What am I missing? Thankyou

Private Sub cmdDrawingNumberRpt_Click()
On Error GoTo Err_cmdDrawingNumberRpt_Click
Const conUserCancelled = 2501
DoCmd.OpenReport &quot;SheetNumber&quot;, acPreview
Exit_cmdDrawingNumberRpt_Click:
Exit Sub
Err_cmdDrawingNumberRpt_Click:
If Err <> conUserCancelled Then
MsgBox Err.DESCRIPTION
End If
Resume Exit_cmdDrawingNumberRpt_Click
End Sub
 
I cannot get this working either - it is so frustrating! It is like the two different pieces of code - one opening the report, and the second executing onNoData - are conflicting with each other.

Any help would be much appreciated!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top