Set Visible property based on text box value

  • Thread starter Thread starter tmc
  • Start date Start date
T

tmc

I have a textbox that is a date field. I'd like to have
the box and its related label be invisible if there is a
value in the field and if the field is null then be
visible. This must be easy to do but I'm new to VBA
syntax and haven't been able to figure it out.

Thanks
 
I presumed you are talking about TextBox and Label Control on a Form. In
this case, you can use the Form_Current Event. Something like:

***Untested***
Private Sub Form_Current()
With Me
If IsNull(.txtDate.Value) = True Then
.lblDate.Visible = True
.txtDate.Visible = True
Else
.lblDate.Visible = False
.txtDate.Visible = False
End With
End Sub
****

There are some other fancy coding to make the code shorter but the above is
clearer (for someone who wants to learn VBA syntax).
 
Back
Top