Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Don't display report if no records 1

Status
Not open for further replies.

annie52

Technical User
Mar 13, 2009
164
US
I have an option group on my menu for the user to choose from available reports. When they click on a command button, a Select Case displays the appropriate report. When there are no records, I want to display a message rather than opening the report.

Since I'm opening the report via a command button, I can't use the On No Data event. I suspect I need to insert an IF statement in the Select Case but I'm not sure just how to code this.
 
Thanks for the reply and the great question. Here's what I put in the On No Data event for the report. I don't get an error but the message box displays twice and then the report opens anyway.

Private Sub Report_NoData(Cancel As Integer)
On Error GoTo ErrAnn

MsgBox "Data integrity is fine. Stop worrying!"

Exit_Report_NoData:
Exit Sub

ErrAnn:
MsgBox "Error number " & Err.Number & ": " & Err.Description
Resume Exit_Report_NoData

End Sub
 
Ah - you need to cancel the opening, too:

[tt]Private Sub Report_NoData(Cancel As Integer)
On Error GoTo ErrAnn

MsgBox "Data integrity is fine. Stop worrying!"
cancel = true
Exit_Report_NoData:
Exit Sub

ErrAnn:
MsgBox "Error number " & Err.Number & ": " & Err.Description
Resume Exit_Report_NoData
End Sub[/tt]

Then, in the errorhandler of the calling sub, do something likle

[tt]ErrAnn:
If Err.Number <> 2501 Then
MsgBox "Error number " & Err.Number & ": " & Err.Description
End If
Resume YourExitHandler[/tt]

Roy-Vidar
 
Thank you so much! This works wonderfully!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top