Set Visible property based on text box value

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
 
V

Van T. Dinh

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).
 

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