No Data property

Posted on 2012-09-17
Last Modified: 2012-09-17
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
Question by:DatabaseDek
    LVL 119

    Expert Comment

    by:Rey Obrero
    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

    Author Comment

    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
    LVL 61

    Accepted Solution

    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


    Author Closing Comment

    Great thank you!!

    LVL 61

    Expert Comment


    Glad to help.

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    This article is a continuation or rather an extension from Cascading Combos ( and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
    I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now