Hide label if subreport has no records?

  • Thread starter Thread starter SusanV
  • Start date Start date
S

SusanV

Hi all,

Fairly simple one I think, but I can't seem to get it right.

I have a subreport which does not always contain any data, and I would like
to set the label for the subreport to not visible if the subreport doesn't
contain any records. (Users seem to think there should be data there if the
label shows)

TIA,

Susan
 
SusanV said:
I have a subreport which does not always contain any data, and I would like
to set the label for the subreport to not visible if the subreport doesn't
contain any records. (Users seem to think there should be data there if the
label shows)


Use a line of code in the Format event of the section
containing the subreport:

Me.thelabel.Visible = Me.subreportcontrol.Report.HasData
 
Report.HasData - that's what I was looking for! Thanks Marshall - I'll give
that a shot first thing!

Susan
 
Criminy this isn't working - Run-time error '2455' You entered an expression
that has an invalid reference to the property Form/Report"

The code I'm using is (I have the code in the On Open event of the report):
Me.lblNewPrec.Visible = Me.subrepLCodeNewPrec.Report.HasData

main report name is repLSGCode (based on a stored query)
subreport label is lblNewPrec
subreport is subrepLCodeNewPrec

When typing the line of code with all lowercase the VBA Editor IS resolving
the controls to there proper case and compiling the code produces no errors.

Breaking out each part, the error is on the second part:
Me.subrepLCodeNewPrec.Report.HasData

The visible part is fine when set to true or false of itself.

What am I doing wrong??? <frustrated>

Thanks again,

Susan


SusanV said:
Report.HasData - that's what I was looking for! Thanks Marshall - I'll
give that a shot first thing!

Susan
 
Oh, btw, if I place the code in the On Activate event, no error but it
doesn't do anything. Error is the same in the On Page event...

SusanV said:
Criminy this isn't working - Run-time error '2455' You entered an
expression that has an invalid reference to the property Form/Report"

The code I'm using is (I have the code in the On Open event of the
report):
Me.lblNewPrec.Visible = Me.subrepLCodeNewPrec.Report.HasData

main report name is repLSGCode (based on a stored query)
subreport label is lblNewPrec
subreport is subrepLCodeNewPrec

When typing the line of code with all lowercase the VBA Editor IS
resolving the controls to there proper case and compiling the code
produces no errors.

Breaking out each part, the error is on the second part:
Me.subrepLCodeNewPrec.Report.HasData

The visible part is fine when set to true or false of itself.

What am I doing wrong??? <frustrated>

Thanks again,

Susan
 
As I said before, the code must be in the Format event
procedure of the section containing the subreport.
 
Stupid me, that's what I get for trying to write code so early in the
morning - I didn't even SEE that part. Duh!

Thanks again for your help and above all your patience!!!

Susan

Marshall Barton said:
As I said before, the code must be in the Format event
procedure of the section containing the subreport.
--
Marsh
MVP [MS Access]

Criminy this isn't working - Run-time error '2455' You entered an
expression
that has an invalid reference to the property Form/Report"

The code I'm using is (I have the code in the On Open event of the
report):
Me.lblNewPrec.Visible = Me.subrepLCodeNewPrec.Report.HasData

main report name is repLSGCode (based on a stored query)
subreport label is lblNewPrec
subreport is subrepLCodeNewPrec

When typing the line of code with all lowercase the VBA Editor IS
resolving
the controls to there proper case and compiling the code produces no
errors.

Breaking out each part, the error is on the second part:
Me.subrepLCodeNewPrec.Report.HasData

The visible part is fine when set to true or false of itself.

What am I doing wrong??? <frustrated>
 
No worries, we've all been there.

What I really want to hear is that it works ;-)
 
Oh sorry!! Yes it worked beautifully! One less thing for users to yip at me
about - thank you!!

Susan

Marshall Barton said:
No worries, we've all been there.

What I really want to hear is that it works ;-)
--
Marsh
MVP [MS Access]

Stupid me, that's what I get for trying to write code so early in the
morning - I didn't even SEE that part. Duh!

Thanks again for your help and above all your patience!!!
 
Back
Top