No Data property

I have a Cancel event in a reports No Data property. How do you allow report to be opened if there is data in the same report's sub report
Derek BrownMDAsked:
Who is Participating?
 
mbizupCommented:
I've tried that in a few variations.

This seems to work in the Subreport's Open Event:


Private Sub Report_Open(Cancel As Integer)
    If Me.HasData = False Then
        MsgBox "No Data!"
        DoCmd.Close acReport, Me.Parent.Name
    End If
End Sub

Open in new window



You'll have to add error handling in whatever code opens this report, as cancelling/closing a report while it is opening will raise error 2501.

Your error handling can be as simple as:

On Error Resume Next
Docmd.OpenReport "YourReportName", acViewPreview

Open in new window

0
 
Rey Obrero (Capricorn1)Commented:
try this logic,
in the Nodata event of your report check if there is data in your subreport ,

if there is data set Cancel=false,
    else, set cancel=true
0
 
Derek BrownMDAuthor Commented:
I have tried this in a thousand variations.

If Me!MySubReortName.Report.HasData = 0 Then

as explained in the help file. It doesn't work
0
 
Derek BrownMDAuthor Commented:
Great thank you!!

Derek
0
 
mbizupCommented:
:)

Glad to help.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.