Blank Report Message

A

Ann

I am working with Access 2002 trying to add code to a report when it opens to
tell the user when there aren't any records to display. It works fine on a
regular report, but I have a report that starts out blank, no query and no
fields, but has two subs on it. I needed to do this because of calculations
done in the footer on different fields. I have added the following code to
the button that opens the report, rptQuestionsOneAndFive.

Private Sub Command30_Click()
On Error GoTo ErrorOpen
DoCmd.OpenReport "rptCalendar", acViewPreview

ExitOpen:
Exit Sub

ErrorOpen:
If Err = 2501 Then
Resume ExitOpen
Else
MsgBox Err.Description
Resume ExitOpen
End If

End Sub

I then added the following code to both of the subreports, subrptQuestionOne
and subrptQuestionFive:

Private Sub Report_NoData(Cancel As Integer)
On Error GoTo ErrorHandler
MsgBox "There are currently no records to display.", vbOKOnly
Cancel = True

ExitReport:
Exit Sub

ErrorHandler:
MsgBox Err.Description
Resume ExitReport

End Sub

All I get is a blank report since the subs are on a blank report. Is there
a way to still have the message appear if the report still opens but is
blank. I'm a beginner in VB so hopefully it won't be too complex if it can
be done. Thanks in advance for the help.
 
A

Ann

I have a typo from copying from a different report that works. The following
line should be:

DoCmd.OpenReport "rptQuestionsOneAndFive", acViewPreview

and not

DoCmd.OpenReport "rptCalendar", acViewPreview
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top