[Last Call] Learn how to a build a cloud-first strategyRegister Now


No Data property

Posted on 2012-09-17
Medium Priority
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
  • 2
  • 2
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 38406560
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

ID: 38406583
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

mbizup earned 2000 total points
ID: 38407204
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

ID: 38407926
Great thank you!!

LVL 61

Expert Comment

ID: 38407930

Glad to help.

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
Explore the ways to Unlock VBA Project Password Excel 2010 & 2013 documents. Go through the article and perform the steps carefully to remove VBA Excel .xls file.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

830 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