NoData Event

  • Thread starter Thread starter Richard
  • Start date Start date
R

Richard

Hi

I have form that calls for a report. And if the report has nodata, the
nodata event is set to cancel=true.

The problem is, how do I stop the msg that comes after it that says "The
OpenReport action was cancelled"

Thanks in advance
Richard
 
In a Form or Standard module. NOT in the Report module.

Sub PrintReport()
On Error GoTo ErrHandler

' <Insert Code to open report>

ExitHere:
Exit Sub
ErrHandler:
Select Case Err.Number
Case 2501
' Do nothing, exit gracefully: Action cancelled (possibly by
Report_NoData event)
Resume ExitHere
Case Else
' <Insert MsgBox code or whatever you want to happen on any
*other* kind of error>
Resume ExitHere
End Select
End Sub
 
I got this from a previous post. It does display a message
that there is no data and the exitss

(Q) How can I close a report automatically if there's no
data returned by the underlying query?

(A) You can use the Report's OnNoData event for this.
For example, the following code

'************* Code Start **************
** Put this on the NoData event in report

Private Sub Report_NoData(Cancel As Integer)

MsgBox "No data found! Closing report."

Cancel = True
End Sub

'************* Code End *************

will automatically close the report if there are no
records in the underlying source. However, if you're
opening the report from code behind a form, you need to
handle the error that's generated as a result.

'*********** Code Start ************

Private Sub TestNoData_Click()

On Error Resume Next ' change On errot to this - this
statement is all you need
DoCmd.OpenReport "SomeReport", acViewPreview
If Err = 2501 Then Err.Clear

End Sub

'*********** Code End ************

Jim
 
Thanks all

Appreciate it

Richard

Jim/Chris said:
I got this from a previous post. It does display a message
that there is no data and the exitss

(Q) How can I close a report automatically if there's no
data returned by the underlying query?

(A) You can use the Report's OnNoData event for this.
For example, the following code

'************* Code Start **************
** Put this on the NoData event in report

Private Sub Report_NoData(Cancel As Integer)

MsgBox "No data found! Closing report."

Cancel = True
End Sub

'************* Code End *************

will automatically close the report if there are no
records in the underlying source. However, if you're
opening the report from code behind a form, you need to
handle the error that's generated as a result.

'*********** Code Start ************

Private Sub TestNoData_Click()

On Error Resume Next ' change On errot to this - this
statement is all you need
DoCmd.OpenReport "SomeReport", acViewPreview
If Err = 2501 Then Err.Clear

End Sub

'*********** Code End ************

Jim
 
Back
Top