Solved

Sub Report and Display Text on No Data

Posted on 2013-11-29
4
696 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
  • 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

758 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