label visible depending upon value in another control

  • Thread starter Thread starter Tony Williams
  • Start date Start date
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
 
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
 
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
 
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.
 
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.
 
Back
Top