On Thu, 5 Nov 2009 15:47:13 -0500, RipperT wrote:
> I have a minor annoyance I'd like to get rid of. I have a button that opens
> a report, but if no data is available, then the NoData event kicks in. I
> found a nifty trick that cancels error messages with forms but it doesn't
> work with this report:
>
> Private Sub Report_NoData(Cancel As Integer)
> On Err GoTo Err_Report_NoData
>
> MsgBox " No data to display. ", vbOKOnly + vbExclamation, "No
> Data"
> Cancel = True
>
> Exit_Report_NoData:
> Exit Sub
>
> Err_Report_NoData:
> 'if action is canceled by user, suppress error msg
> Const conErrDoCmdCancelled = 2501
> If (Err = conErrDoCmdCancelled) Then
> Resume Exit_Report_NoData
> End If
> End Sub
>
> After user clicks out of the custom msgbox, Access displays this one:
> "The OpenReport Action was canceled."
> Can I get rid of it?
> Thanks,
> Ripper
Sure, but you placed the error handling code in the wrong place.
You need to do this in the form code event that you use to open the
report, not in the report itself.
Code the Form event (i.e. a Command Button click event?):
Private Sub CommandName_Click()
On Error GoTo Err_Handler
DoCmd.OpenReport "ReportName", acPreview
Exit_Sub:
Exit Sub
Err_Handler:
If Err = 2501 Then
Else
MsgBox "Error# " & Err.Number & " " & Err.Description
End If
Resume Exit_Sub
End Sub
You can remove the error handling completely from the Report's
OnNoData event.
Private Sub Report_NoData(Cancel As Integer)
MsgBox " No data to display. ", vbOKOnly + vbExclamation, "No
Data"
Cancel = True
End Sub
--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail