making a subform control label invisible

P

Paul James

I've got a report with three subreports, and when there are no records in
any of the subreports, the subreport does not appear in the main report.
However, the subreport label remains visible, even when there is nothing in
the subreport.

I would like to for the label to become invisible when there are no records
in the subreport. Is there a way to set the visible property of these
labels to "No" in VBA when there are no records in the subreport?

Thanks in advance,

Paul
 
G

Gina

Perhaps...

If(IsNull([Me.txtField1])) then
Me.lblField2.Visible = False
Else
Me.lblField2.Visible = True
End If
 
M

Marshall Barton

Paul said:
I've got a report with three subreports, and when there are no records in
any of the subreports, the subreport does not appear in the main report.
However, the subreport label remains visible, even when there is nothing in
the subreport.

I would like to for the label to become invisible when there are no records
in the subreport. Is there a way to set the visible property of these
labels to "No" in VBA when there are no records in the subreport?


In the Format event of the section containing the
subreports:

Me.label1.Visible = Me.subreport1.HasData
Me.label2.Visible = Me.subreport2.HasData
 
P

Paul James

Since I'm trying to test for no records in a subreport, the expression will
have to involve either the subreport name and/or the subreport control name.
I'd know how to refer to this if it were a form by using an expression like

Forms![main form name]![subform control name].Form![control name].

But in this case I'm trying to test for the absence of any records in a
subreport, and I've tried several different variations of the above such as

Reports![main report name]![subreport name].Report![name of control in
subreport]

But none of them work.

Any ideas?
 
P

Paul James

I tried your suggestion, March, but it crashes on the "Me.subreport1" part,
saying "Microsoft Access can't find the field 'subreport1' referred to in
your expression.

Since this object is a subreport, is there some modification of
"Me.label1.Visible = Me.subreport1.HasData" that might work? I've tried
variations of the structure used to refer to subform controls in a main form
which I described in my reply to Gina in another branch of this
conversation, but I haven't been able to get anything to work.

Another issue here is that I'm trying to identify occurrences where there
are no records in the subreport. I suppose one way is to say that a
specific field in the subreport is null, but my preference would be to refer
to the subreport explicitly, and establish whether there are any records in
it, without referring specifically to any controls in the subreport.

Any idea how to accomplish this?
 
M

Marshall Barton

Paul said:
I tried your suggestion, March, but it crashes on the "Me.subreport1" part,
saying "Microsoft Access can't find the field 'subreport1' referred to in
your expression.

Since this object is a subreport, is there some modification of
"Me.label1.Visible = Me.subreport1.HasData" that might work?

Arrggghhhh. I left out the report property. Try this

Me.label1.Visible = Me.subreportcontrol.REPORT.HasData


Another issue here is that I'm trying to identify occurrences where there
are no records in the subreport. I suppose one way is to say that a
specific field in the subreport is null, but my preference would be to refer
to the subreport explicitly, and establish whether there are any records in
it, without referring specifically to any controls in the subreport.

No, don't do this. If there's no data then the controls in
the subreport never get any value not even Null.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top