?
Solved

Sub Report and Display Text on No Data

Posted on 2013-11-29
4
Medium Priority
?
774 Views
Last Modified: 2013-11-29
Experts,

I have a subreport with a No Data event:
Private Sub Report_NoData(Cancel As Integer)

    MsgBox "No Data"
    Cancel = True

End Sub

The msgbox displays when I open the report separately but as expected the sub report msg box will not display when opening the Parent report and I do not want the msg box to display.  Instead, I want the subreport to display text "No Data" so that it could be seen on the printout.  

How can I do this?    thank you
0
Comment
Question by:pdvsa
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 58

Assisted Solution

by:Jim Dettman (Microsoft MVP/ EE MVE)
Jim Dettman (Microsoft MVP/ EE MVE) earned 1000 total points
ID: 39685925
Add a label or text control on the parent that's normally hidden, then on the NoData event for the sub report, make that control visible.

Jim.
0
 
LVL 61

Accepted Solution

by:
mbizup earned 1000 total points
ID: 39685926
Try this -

1.  Remove or comment out your existing subreport code

2.  Place a label in your MAIN report, immediately above the subreport, and call it lblNoData, captioning it something like "No Data In Subreport"

3.  Place this in the On Format event of your MAIN report's Detail section:

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If Me.SubreportControlName.Report.HasData = False Then
    Me.SubreportControlName.Visible = False
    Me.lblNoData.Visible = True
End If
End Sub

Open in new window

0
 
LVL 58
ID: 39685930
You can also do it another way, which is by setting a text control in the parent source to:

=IIF([SubReport].[Report].[HasData],Null,"NO DATA")

 I think that's a little less obvious though then doing it in the subreport.

Jim.
0
 

Author Closing Comment

by:pdvsa
ID: 39686208
thank you.  I put the code in the Footer Format event because this is where the subreport resides.   I split points because both said the same but mbizup made it a bit easier with the codes.
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
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…
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.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Suggested Courses

752 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