NoData Event

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
 
G

George Nicholson

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
 
J

Jim/Chris

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
 
R

Richard

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top