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

Close Report On No Data

How To

Close Report On No Data

by  Garridon  Posted    (Edited  )
If your report doesn't have any records, you may want to cancel it instead of letting the user see a blank page.

Insert this code behind the button you use to open the report. (cmdButton refers to the name of your button)

Private Sub cmdButton_Click()
On Error GoTo ErrorHandler

DoCmd.OpenReport "rptName", acViewPreview

ExitHandler:
Exit Sub

ErrorHandler:

' This traps the Output to Error message
If Err = 2501 Then
Resume ExitHandler

Else
MsgBox Err.Description
Resume ExitHandler

End If

End Sub

Insert this code in the On NoData event procedure of the report:

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

MsgBox "There are currently no records", vbOKOnly, _
"Title of Message Box"

Cancel = True

ExitHandler:
Exit Sub

ErrorHandler:
MsgBox Err.Description
Resume ExitHandler

End Sub
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top