text box 2 appears when text box 1 is filled in

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have the following code to hide text box txtStreetAddress2 if text box
txtStreetAddress1 is empty.

Private Sub Form_Current()
txtStreetAddress1.SetFocus: If txtStreetAddress1.Text = "" Then
txtStreetAddress2.Visible = False
End Sub

It works, but how do I make txtStreetAddress2 reappear when
txtStreetAddress1 has been filled in?

I'm not really sure which is the correct property field for this.

Thank you

Peter
 
Dear Peter:

You must set it both visible and not visible for it to work in all cases
where needed. The current event is one. The exit event of the first text
box is another.

I recommend this:

txtStreetAddress2.Visible = (txtStreetAddress1.Text <> "")

The condition inside the parens is evaluated and the resulting boolean
assigned to visibility. This turns it on and off, and can be used for both
events. That way, if the form ever gets saved as invisible, it will still
work next time the form opens.

Tom Ellison
 
Back
Top