Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Microsoft: Access Reports FAQ

How To

Close Report On No Data by Garridon
Posted: 6 Mar 02 (Edited 20 May 03)

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

    Exit Sub


' This traps the Output to Error message
    If Err = 2501 Then
    Resume ExitHandler
        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
    Exit Sub

    MsgBox Err.Description
    Resume ExitHandler

End Sub

Back to Microsoft: Access Reports FAQ Index
Back to Microsoft: Access Reports Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close