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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

No Data Problem

Status
Not open for further replies.

Brogrim

Technical User
Jul 28, 2000
184
IE
If my report returns no records I want to use the No Data event to produce a message and close the report. I ma entering the following

Private Sub Report_NoData(Cancel As Integer)
MsgBox "There are no records for this report", vbInformation, "DBA"

Docmd.close acReport, "report 1"
End Sub

I keep getting a Debug message
 
The code should read:
Code:
[COLOR=blue]Private Sub[/color] Report_NoData(Cancel [COLOR=blue]As Integer[/color])
  MsgBox "There are no records for this report", vbInformation, "DBA"
  Cancel = [COLOR=blue]True
End Sub[/color]
 
You also need to trap errors in the code that opens the report. The canceling of a report will cause error 2501 to the code that opens the report.

Duane
MS Access MVP
Find out how to get great answers faq219-2884.
 
Thanks bytemyzer, that worked but I now get an error as described by dhookom.

How do i tarp errors in the code that opens the report.

Thanks
 
In that event, the code which opens the report should read something like this:
Code:
[COLOR=blue]On Error Resume Next[/color]
DoCmd.OpenReport "Report1", acPreview
[COLOR=blue]If[/color] Err.Number <> 0 [COLOR=blue]And[/color] Err.Number <> 2501 [COLOR=blue]Then[/color]
    MsgBox Err.Number & ":" & Err.Description, vbCritical
    [COLOR=blue]Exit Function
End If[/color]
 
Will this not produce another message box
 
Brogrim, it might be nice if you actually tried the code before asking that question. If you try the code as I wrote it, it will only produce an error if there is something else wrong, not if the report's OpenEvent is cancelled. Please try it first, then get back to me.

Pardon me if I sound overly irritated, but it wouldn't hurt to take some things on faith until you've actually tried them, as opposed to taking the negative approach initially when someone offers you help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top