Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Sub Report and Display Text on No Data

Posted on 2013-11-29
4
Medium Priority
?
784 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
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.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

604 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