Solved

Sub Report and Display Text on No Data

Posted on 2013-11-29
4
745 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 57

Assisted Solution

by:Jim Dettman (Microsoft MVP/ EE MVE)
Jim Dettman (Microsoft MVP/ EE MVE) earned 250 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 250 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 57
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

Independent Software Vendors: 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

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

733 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