By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,397 Members | 1,482 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,397 IT Pros & Developers. It's quick & easy.

How To hide a subreport?

P: 16
How To hide a subreport?
I found how to know if the subreport has no data
(Me.subreportname.Report.HasData)
what I didn't find is how to make the sub report unvisibile if it has no data.
I tried:
If Not Me.subreportname.Report.HasData then
Me.subreportname.Report.Visible = False
End If
but it gave me an error
Sep 9 '07 #1
Share this Question
Share on Google+
11 Replies


lee123
100+
P: 556
hi there you could use this

Expand|Select|Wrap|Line Numbers
  1. if subreportname then
  2.    subreportname.visible = true
  3. else
  4.   subreportname.visible = false
  5. end if
lee123
Sep 9 '07 #2

MMcCarthy
Expert Mod 10K+
P: 14,534
The first time you refer to the subreport you are referring to the report itself so you need the .Report

However, the second time you are referring to the subreport object so you don't use .Report

You also have to allow for the true event.

Expand|Select|Wrap|Line Numbers
  1. If  Me.subreportname.Report.HasData then
  2.     Me.subreportname.Visible = True
  3. Else
  4.     Me.subreportname.Visible = False
  5. End If
  6.  
Sep 9 '07 #3

P: 16
Thanks for your attention, the code was OK,
but still I have a problem, since my target was to save the space that the balnk subreport takes' and although the sub report was unvisible' still the page was with large blank space, in the palce that the subreports was supposed to sit.
Do you have any idea how to save the blank space?
Thanks.
Sep 10 '07 #4

FishVal
Expert 2.5K+
P: 2,653
Thanks for your attention, the code was OK,
but still I have a problem, since my target was to save the space that the balnk subreport takes' and although the sub report was unvisible' still the page was with large blank space, in the palce that the subreports was supposed to sit.
Do you have any idea how to save the blank space?
Thanks.
Hi, Daniel.

Try the following.
  • Set subreport control .CanGrow = Yes
  • Reduce subreport control height to possible minimum
  • Handle subreport.Report "On No Data" event
    Expand|Select|Wrap|Line Numbers
    1. Private Sub Report_NoData(Cancel As Integer)
    2.     Cancel = True
    3. End Sub
    4.  
Sep 10 '07 #5

P: 16
Thanks a lot, but didn't work.
As much as I understood from searching google, the
"ON NO DATA" event, does not fire in the subreport.
Sep 10 '07 #6

FishVal
Expert 2.5K+
P: 2,653
Thanks a lot, but didn't work.
As much as I understood from searching google, the
"ON NO DATA" event, does not fire in the subreport.
LOL. It is really so.

But it works without handling event.
At least in my test:
Several bound textboxes
Unbound label
Unbound checkbox

Did you shrink an empty report area having reduced subreport control height?
Sep 10 '07 #7

P: 16
Hi,
what did you mean "But it works without handling event." ?
Sep 10 '07 #8

FishVal
Expert 2.5K+
P: 2,653
Hi,
what did you mean "But it works without handling event." ?
Screenshot in attachment.
Attached Images
File Type: jpg Shot.JPG (15.9 KB, 1295 views)
Sep 10 '07 #9

P: 47
Daniel is correct that you don't need an event to hide the subreport. Just make the height of the subreport zero in design view and set CanGrow=Yes and CanShrink=Yes in the properties of the sub report.

However, you must also set CanGrow=Yes and CanShrink=Yes for the Report section which contains the subreport (|Detail, Report Footer or whatever)
Sep 10 '07 #10

P: 16
Thanks you all for your attention and time, It worked.
Sep 10 '07 #11

FishVal
Expert 2.5K+
P: 2,653
You are welcome.

Kind regards,

Fish
Sep 10 '07 #12

Post your reply

Sign in to post your reply or Sign up for a free account.