On No Data

  • Thread starter Thread starter Melissa
  • Start date Start date
M

Melissa

Any help is appreciated.

I have two issues:

1. My report's On No Data Event contains code for msg
box. It triggers two iterations of the msg box when
conditions are met. I tried with the only VBA code
anywhere on the report at the On No Data event, which
contained only one line (msgbox "test") and even that
returned the message box twice. How do I stop the second
iteration. This occurs when opening the report as a stand-
alone report.

2. How do I close the report when the On No Data
condition is met?

Should I use a different test method for each of these?
Not sure how to go here...I am not professional at this.

Thanks.
Melissa
 
Fred said: How would any one know, as you haven't posted
the OnNoData code. Got attitude? Not very helpful to me;
this is a help newsgroup, right?

I wasn't referring to On No Data test. Perhaps you can
re-read my post and realize I was referring to using the
On No Data as the test...or something else, not the code
within the event.

However, my code is:

Private Sub Report_NoData(Cancel As Integer)
Dim msg, style, title, response
msg = "There are no receipts for your date range."
style = vbOKOnly
title = "No data."
response = MsgBox(msg, style, title)
End Sub

I'm still in need of constructive guidance. Thanks for
any help you might give.
Melissa
 
Looks like you did not set Cancel=True.
That is usually the only thing I put in my reports.
The message box is displayed in the error handler of the code that calls the
reports.
====================================================

This is a good way to handle the no data event for a report.
Note that the Print Preview button has to trap error 2501 when the code sets
Cancel=True.
====================================================
Private Sub Print_Preview_Click()
On Error GoTo Err_Print_Preview_Click

Dim DocName As String
DocName = [Forms]![Report Menu]![RptList]
DoCmd.OpenReport DocName, acViewPreview

Exit_Print_Preview_Click:
Exit Sub

Err_Print_Preview_Click:
Select Case Err.Number
Case 2501
MsgBox ("There is no data for this report.")
Case Else
MsgBox ("Error # " & Str(Err.Number) & " was generated by " &
Err.Source & Chr(13) & Err.Description)
Resume Exit_Print_Preview_Click
End Select

End Sub
====================================================
Private Sub Report_NoData(Cancel As Integer)
Cancel = True
End Sub
====================================================
 
Thanks for the help,Joe. It works beautifully. I learned
once again from you guys.
Melissa


-----Original Message-----
Looks like you did not set Cancel=True.
That is usually the only thing I put in my reports.
The message box is displayed in the error handler of the code that calls the
reports.
====================================================

This is a good way to handle the no data event for a report.
Note that the Print Preview button has to trap error 2501 when the code sets
Cancel=True.
====================================================
Private Sub Print_Preview_Click()
On Error GoTo Err_Print_Preview_Click

Dim DocName As String
DocName = [Forms]![Report Menu]![RptList]
DoCmd.OpenReport DocName, acViewPreview

Exit_Print_Preview_Click:
Exit Sub

Err_Print_Preview_Click:
Select Case Err.Number
Case 2501
MsgBox ("There is no data for this report.")
Case Else
MsgBox ("Error # " & Str(Err.Number) & " was generated by " &
Err.Source & Chr(13) & Err.Description)
Resume Exit_Print_Preview_Click
End Select

End Sub
====================================================
Private Sub Report_NoData(Cancel As Integer)
Cancel = True
End Sub
====================================================
--
Joe Fallon
Access MVP



Melissa said:
Any help is appreciated.

I have two issues:

1. My report's On No Data Event contains code for msg
box. It triggers two iterations of the msg box when
conditions are met. I tried with the only VBA code
anywhere on the report at the On No Data event, which
contained only one line (msgbox "test") and even that
returned the message box twice. How do I stop the second
iteration. This occurs when opening the report as a stand-
alone report.

2. How do I close the report when the On No Data
condition is met?

Should I use a different test method for each of these?
Not sure how to go here...I am not professional at this.

Thanks.
Melissa


.
 
Hurray!
I got one right.

Oops. Don't read that!
--
Joe Fallon
Access MVP



Melissa said:
Thanks for the help,Joe. It works beautifully. I learned
once again from you guys.
Melissa


-----Original Message-----
Looks like you did not set Cancel=True.
That is usually the only thing I put in my reports.
The message box is displayed in the error handler of the code that calls the
reports.
====================================================

This is a good way to handle the no data event for a report.
Note that the Print Preview button has to trap error 2501 when the code sets
Cancel=True.
====================================================
Private Sub Print_Preview_Click()
On Error GoTo Err_Print_Preview_Click

Dim DocName As String
DocName = [Forms]![Report Menu]![RptList]
DoCmd.OpenReport DocName, acViewPreview

Exit_Print_Preview_Click:
Exit Sub

Err_Print_Preview_Click:
Select Case Err.Number
Case 2501
MsgBox ("There is no data for this report.")
Case Else
MsgBox ("Error # " & Str(Err.Number) & " was generated by " &
Err.Source & Chr(13) & Err.Description)
Resume Exit_Print_Preview_Click
End Select

End Sub
====================================================
Private Sub Report_NoData(Cancel As Integer)
Cancel = True
End Sub
====================================================
--
Joe Fallon
Access MVP



Melissa said:
Any help is appreciated.

I have two issues:

1. My report's On No Data Event contains code for msg
box. It triggers two iterations of the msg box when
conditions are met. I tried with the only VBA code
anywhere on the report at the On No Data event, which
contained only one line (msgbox "test") and even that
returned the message box twice. How do I stop the second
iteration. This occurs when opening the report as a stand-
alone report.

2. How do I close the report when the On No Data
condition is met?

Should I use a different test method for each of these?
Not sure how to go here...I am not professional at this.

Thanks.
Melissa


.
 
Back
Top