label visible depending upon value in another control

T

Tony Williams

I have a label on a form that I want to be visible only if the value of a
combo box control on the form is not null. I have tried this
Private Sub cmbHazards_AfterUpdate()

If Not IsNull(Me.cmbHazards) Then
Me.lblcaution.Visible
End If

End Sub

However it would appear I can't use the Visible property with a label?
Can anyone help?
Thanks
Tony
 
B

Brendan Reynolds

Tony Williams said:
I have a label on a form that I want to be visible only if the value of a
combo box control on the form is not null. I have tried this
Private Sub cmbHazards_AfterUpdate()

If Not IsNull(Me.cmbHazards) Then
Me.lblcaution.Visible
End If

End Sub

However it would appear I can't use the Visible property with a label?
Can anyone help?
Thanks
Tony


Sure you can, but you have to assign a value to the property. Try this ...

Me.lblcaution.Visible = (Not IsNull(Me.cmbHazards))

A slightly more verbose but perhaps easier to understand way of doing the
same thing is ...

If Not IsNull(me.cmbHazards) Then
Me.lblcaution.Visible = True
Else
Me.lblcaution.Visible = False
End If
 
T

Tony Williams

Thanks Brendan. I've used the second version as I can understand what's
happening there. However it doesn't work? The label is always visible. I've
put the code in the AfterUpdate event of the combo box. Is that the right
place?
Thanks
Tony
 
F

fredg

I have a label on a form that I want to be visible only if the value of a
combo box control on the form is not null. I have tried this
Private Sub cmbHazards_AfterUpdate()

If Not IsNull(Me.cmbHazards) Then
Me.lblcaution.Visible
End If

End Sub

However it would appear I can't use the Visible property with a label?
Can anyone help?
Thanks
Tony

Private Sub cmbHazards_AfterUpdate()
Me.lblCaution.Visible = Not IsNull(Me![cmbHazards])
End If

Pace the same code in the Form's Current event.
The label will become visible or not visible after you exit the combo
box control.
 
T

Tony Williams

Thanks Fred worked just fine!
Tony

fredg said:
I have a label on a form that I want to be visible only if the value of a
combo box control on the form is not null. I have tried this
Private Sub cmbHazards_AfterUpdate()

If Not IsNull(Me.cmbHazards) Then
Me.lblcaution.Visible
End If

End Sub

However it would appear I can't use the Visible property with a label?
Can anyone help?
Thanks
Tony

Private Sub cmbHazards_AfterUpdate()
Me.lblCaution.Visible = Not IsNull(Me![cmbHazards])
End If

Pace the same code in the Form's Current event.
The label will become visible or not visible after you exit the combo
box control.
 

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