View Full Version : Invisible Text Box


Kevin Field
06-29-2010, 12:46 AM
Is it possible to set a text box on a report to only appear if another text box is not null?

I have a hunch that this is something to do with setvalue or similar in a macro? or even in the basic query the report is based on.

Any ideas?

Thanks!

vbaInet
06-29-2010, 01:10 AM
On the SECTION where the control is placed, use this code in the ON FORMAT event of that section:

txtBoxToHide.visible = Not IsNull(txtBoxToTest.value)

Kevin Field
06-29-2010, 01:19 AM
I have used that code and replaced it with the names of the 'labels' which i need to make invisible. Sorry for the confusion in my topic post. I currently have this:

Label30.Visible = Not IsNull(Text21.Value)

Does this look right to you? Label30 needs to dissapear if Text21 is null.

Also, how do i add a second label to the above. I have two labels on the sub report which need to be blank if text21 is null.

Thanks!

vbaInet
06-29-2010, 01:35 AM
Yes, that's correct. If it's null it would return TRUE but that would make the Visible property True, which is why you need to negate it to FALSE using Not.

Instead of using text21.value you can refer to the field instead.

Use the same code for the other label. It's either you set the visible property of the label or you set the caption to "".

Kevin Field
06-29-2010, 01:46 AM
Apologies for this but it still dosent seem to work.

Here is the Visual Basic code i have on the detail sections ON FORMAT.


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

Label30.Visible = Not IsNull(Text21.Value)
Label31.Visible = Not IsNull(Text21.Value)

End Sub

Any ideas?

vbaInet
06-29-2010, 02:00 AM
Refer to the field instead of the control.

The only reason why it wouldn't work is because your field is returning a zero-length string instead of Null. If you want to test for both cases then use Len.

Label30.Visible = Len([Field] & "")