How to hide and un-hide fields upon condition

P

p-rat

I have a text box on a form and next to it I have another text box
that I want to hide unless there is data in the first text box. So, if
no information is entered in text box 1 then hide text box 2 and vice
versa. Is this easy to do?
 
D

Douglas J. Steele

In the form's Current event, put:

Me.Textbox2.Visible = Len(Me.Textbox1 & vbNullString) > 0

Put the same code in the AfterUpdate event of Textbox1.

If you want the content of Textbox2 to be erased if the content of Textbox1
is, use

Private Sub Textbox1_AfterUpdate()

If Len(Me.Textbox1 & vbNullString) = 0 Then
Me.Textbox2 = Null
Me.Textbox2.Visible = False
Else
Me.Textbox2.Visible = True
End If

End Sub
 
M

Marshall Barton

p-rat said:
I have a text box on a form and next to it I have another text box
that I want to hide unless there is data in the first text box. So, if
no information is entered in text box 1 then hide text box 2 and vice
versa. Is this easy to do?


Most things are easy when you know how ;-)

Generally, this kind of thing is done by using a line of
code in both textbox1's AfterUpdate and in the form's
Current event procedures:

Me.textbox2.Visible = Not IsNull(Me.textbox1)
 

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