Subreports - transparent background?

Hi Experts,

I have a report that contains numerous sub reports.

A couple of the subreports sometimes contain no data - and are therefore not shown on the main report. This leaves a blank space on the overall report which I would like to fill with the message - "No Data Available".

I had thought the easiest way to do this was to put a label on the main report behind these subreports - so that when the subreport was present the label was hidden - and when it wasn't there it was visible. However, the subreports seem to be "transparent" so that you can always see the label in the background.

Any ideas?

Thanks,

Sam
LVL 1
SamBAsked:
Who is Participating?
 
bluelizardCommented:
one more correction:  don't put any code into the subreport's "OnOpen" event (this will only have an influence on the NEXT "detail line", which is not what we want here).  instead, go to the section in the main report that holds the subreport (typically the "detail" section), open that section's properties, and put the following code into the OnFormat event:

  If Me.MySubreport.Report.HasData = True Then
    Me.MyLabel.Visible = False
  Else
    Me.MyLabel.Visible = True
  End If

(again: replace MySubreport with the name of the subreport and MyLabel with the name of your label).

now, it should work... (hopefully... i've said so several times before...)


--bluelizard
0
 
bluelizardCommented:
actually, with the sections' property "BackColor", you can set white as the background color.  but i think this is the default, and i don't event think it's possible to set it to transparent...  so you probably already have the backcolor set to white, but you still might want to check.

possibly, the ordering of the objects is wrong, i.e., your label "no data available" is *in front* of the subreport instead of *behind* it.  try selecting the label and then choosing Format > Send to back


--bluelizard
0
 
Kelvin SparksCommented:
This doesn't help your label issue, but I often want the space the subreport occupies to disappear if there is no data in the subreport. I Set the height property of the subreport to 0.001 cm and its can grow property to true and its border property to transparent. The subreport doesn't appear if there's no data , not does it take any space on the parent  report, but appears with the appropriate length wjhen populated. Don't, howver, put the No Dataq Avaialble label below this very short report as it wiull always appear below it.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
SamBAuthor Commented:
Hi bluelizard

Thanks for your suggestions - I've tried these but no success - the wierd thing is that some elements of the sub report block parts of the label and some do not. It's as if the label has become part of the subreport?

Kelvinsparks - thanks for your advice - I use this on one part of the report - but on this specific sub report I want to "highlight" the fact that the data is not available.

Sam
0
 
bluelizardCommented:
one possibility would be to make the label "no data" invisible and use the subreport's "On No Data" event to make it visible.  i don't have any experience with this, but it might be worth a try.


--bluelizard
0
 
bluelizardCommented:
sorry, forget my last post, i just found this about the OnNoData event in the help:

"This event doesn't occur for subreports. If you want to hide controls on a subreport when the subreport has no data, so that the controls don't print in this case, you can use the HasData property in a macro or event procedure that runs when the Format or Print event occurs."

i'll investigate into this and let you know...


--bluelizard
0
 
bluelizardCommented:
okay, here we go, i run a small test, and here's how it worked:

(1) place the label on your main report (and set it to visible or invisible, it doesn't matter)

(2) in your *subreport*, go to the event "OnOpen", click on the "..." button and write the following code into the sub that shows up:

    If Not (Me.HasData) Then
      Me.Parent.Controls("MyLabel").Visible = True
    Else
      Me.Parent.Controls("MyLabel").Visible = False
    End If

(of course, you have to replace MyLabel with your label's name, but keep the quotes!)

does that work?


--bluelizard
0
 
SamBAuthor Commented:
Thanks Bluelizard,

Your solution works great.

I had also found a rather wierd work around myself - just by changing the subforms back colour from the standard "white" background of "16777215" to something like "16777214" !!!!!!!!!!!

But your code was much more professional!

Thanks again,

SamB
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.