Can't Hide Text Box

K

Keith Wilby

I have the following code in a report's group footer:

Private Sub GroupFooter0_Format(Cancel As Integer, FormatCount As Integer)

If Me.txtMaterials = "" Then
Me.txtMaterials.Visible = False
Me.txtMatHead.Visible = False
End If

End Sub

The idea is that, if the Materials field is empty, the text boxes are hidden
and the controls beneath "move up" the report at run-time. However, when I
run the report only txtMaterials is hidden and txtMatHead remains visible.
If I change txtMatHead's control source to the same one as txtMaterials it
behaves as expected and is hidden. What am I missing here?

Thanks.

Keith.
 
J

John Spencer

I think you need to change the expression to check for Null values (which are
not the same as zero length string values ("").

Private Sub GroupFooter0_Format(Cancel As Integer, FormatCount As Integer)

If Len(Me.txtMaterials & "") = 0 Then
Me.txtMaterials.Visible = False
Me.txtMatHead.Visible = False
End If

End Sub

Or
Private Sub GroupFooter0_Format(Cancel As Integer, FormatCount As Integer)

If IsNull(Me.txtMaterials) Then
Me.txtMaterials.Visible = False
Me.txtMatHead.Visible = False
End If

End Sub

That will cause you a problem because you never set the visible property to
true if Me.TxtMaterials has a value. So once the group footer set the
controls visibility to False then it will stay that way for the rest of the
report.

I might use one of the alternatives below

Me.txtMaterials.Visible = Not IsNull(Me.txtMaterials)
me.txtMatHead.Visible = Not IsNull(Me.txtMaterials)
Or use
Me.txtMaterials.Visible = Len(Me.txtMaterials & "")>0
me.txtMatHead.Visible = Len(Me.txtMaterials & "")>0


John Spencer
Access MVP 2002-2005, 2007-2008
Center for Health Program Development and Management
University of Maryland Baltimore County
 
K

Keith Wilby

John Spencer said:
I think you need to change the expression to check for Null values (which
are not the same as zero length string values ("").
<snip>

<slaps forehead>

Thanks very much John, works a treat. I don't know why I got it into my
head that I had to check for ZLS and not nulls. One of those days. Strange
how it "half" worked though.

Thanks again.

Regards,
Keith.
 
J

John Spencer

I'm guessing that it half-worked because you had the control's can shrink
property set to true. I could definitely be wrong though, since I obviously
have no idea how you set up the report.

John Spencer
Access MVP 2002-2005, 2007-2008
Center for Health Program Development and Management
University of Maryland Baltimore County
 
K

Keith Wilby

John Spencer said:
I'm guessing that it half-worked because you had the control's can shrink
property set to true. I could definitely be wrong though, since I
obviously have no idea how you set up the report.

That would explain it, yes.

Many thanks John.
 
E

Evi

You may also need to add to your code

If Len(Me.txtMaterials & "") = 0 Then
Me.txtMaterials.Visible = False
Me.txtMatHead.Visible = False
Else
Me.txtMaterials.Visible = True
Me.txtMatHead.Visible = True

End If

I don't know about later versions, but in Acc97, if I omitted the Else, the
controls remained invisible even when later records had a value in them.


Evi
 

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