Link to home
Start Free TrialLog in
Avatar of Sanjay
SanjayFlag for United States of America

asked on

VB code to hide/unhide a report's label based on whether or not an embedded subreport does/does not have data to display

How do I write VB code to hide/unhide a report's label based on whether or not an embedded subreport does/does not have data to display.

The name of my embedded subreport is "Child92". Child92 is embedded in my main report's footer.  If the subreport has data to display, then I want Label139 to be visible.  If the subreport has no data to display, then I want Label139 to not be visible.

I have added the following code below on my main report's open property, but the code is not working properly.  At least I have put my logic down on what I am trying to accomplish.  Maybe this code should be in my main report's OnFormat event?

Please help....
Private Sub Report_Open(Cancel As Integer)
    If Child92.Report.Visible Then
        Me.Label139.Visible = True
    Else
        Me.Label139.Visible = False
    End If
End Sub

Open in new window

Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

you can use the report NoData event for this

private sub nodata(cancel as integer)

Label139.visible=false

end sub
ASKER CERTIFIED SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Sanjay

ASKER

Hi C:
Thanks so much for the quick responses.  Label139 is located in my main report's footer.  I will give your recommendation a try and respond back.
Avatar of Sanjay

ASKER

Hi C:

Since the Label is in my footer section, I modified your code to reference the footer and it works.

Private Sub ReportFooter_Format(Cancel As Integer, FormatCount As Integer)
Label139.Visible = Child92.Report.HasData
End Sub

Awesome.  Thanks C.
sxxgupta,
shouldn't { awesome } merit a rating of at least  9 +  ;-)
Avatar of Sanjay

ASKER

Of course.  If I had the option of assigning a 10, I would because you have helped me with a lot of past questions and in the process have helped me improved my VBA learning.
Sanjay