change color when checked

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

Guest

I have created a check box on my form and I want to know if there's a code
that I can use to change the background color of the label once the box is
checked. Thanks.
 
I have created a check box on my form and I want to know if there's a code
that I can use to change the background color of the label once the box is
checked. Thanks.

Yow want to change the color of the label, not the check box itself,
correct?
Code the CheckBox AfterUpdate event:

If Me![CheckBoxName] = -1 Then
Me![LabelName].BackColor = vbRed
Else
Me![LabelName].BackColor = vbWhite
End If

Place the same code in the Form's Current event.
Change the colors to whatever colors you want.
 
Private Sub Check11_AfterUpdate()
Me.Label12.BackStyle = 1
If (Me.Check11) Then
Me.Label12.BackColor = vbRed
Else
Me.Label12.BackColor = vbBlue
End If
End Sub

You'll want to add the code to the Current event procedure of the form, too,
so that the colour is updated as the user navigates through records.
 
Unfortunately, conditional formatting does not work with check boxes and
their labels.
However, you can use a macro or code element to change when GotFocus and
when LostFocus. The macro is one line:
SetValue: action
Control: checkboxlabel.backcolor
Value: 8421376 for teal - copy the color from the label properties in design

Second macro would change the value back to normal color.
 
On the after update event of the check box, write the code

If Me.CheckBoxName Then ' Selected
Me.LableName.BackColor = 255 'change it to red
Else
Me.LableName.BackColor = 16777215 'change it to white
End If
 
Back
Top