Pesty Message Box

  • Thread starter Thread starter Don
  • Start date Start date
D

Don

Hello - I am using the OnNoData event to display message
box saying " No Data matches selection" when no data is
available. Here is my code...

Private Sub Report_NoData(Cancel As Integer)
MsgBox "No Data matches selection", vbOKOnly, "No Data"
Cancel = True
End Sub


When I run the report and there is no data, the message
box appears. After I click okay, a microsoft message box
appears saying "The OpenReport action was canceled" My
question is how do I get rid of this extra Message box?

Thank
DW
 
You need to trap for error # 2501, but not in the report. You have to trap
it in the button that opens the report. Something like this:

Private Sub cmdPreview_Click()
On Error GoTo Err_cmdPreview_Click

Dim stDocName As String

stDocName = "rptGLTable"
DoCmd.OpenReport stDocName, acPreview

Exit_cmdPreview_Click:
Exit Sub

Err_cmdPreview_Click:
If Err.Number = 2501 Then
Resume Next
Else
MsgBox Err.Description
Resume Exit_cmdPreview_Click
End If

End Sub

This is basically the code that the button wizard makes for you with the
addition of the IF statement following Err_cmdPreview_Click:

On my website (see sig below) is a small sample database called
"NoDataInReports" which illustrates.
 
Thank you
-----Original Message-----
You need to trap for error # 2501, but not in the report. You have to trap
it in the button that opens the report. Something like this:

Private Sub cmdPreview_Click()
On Error GoTo Err_cmdPreview_Click

Dim stDocName As String

stDocName = "rptGLTable"
DoCmd.OpenReport stDocName, acPreview

Exit_cmdPreview_Click:
Exit Sub

Err_cmdPreview_Click:
If Err.Number = 2501 Then
Resume Next
Else
MsgBox Err.Description
Resume Exit_cmdPreview_Click
End If

End Sub

This is basically the code that the button wizard makes for you with the
addition of the IF statement following Err_cmdPreview_Click:

On my website (see sig below) is a small sample database called
"NoDataInReports" which illustrates.

--
--Roger Carlson
www.rogersaccesslibrary.com
Reply to: Roger dot Carlson at Spectrum-Health dot Org




.
 
Back
Top