check-box/label color per record check-marked

  • Thread starter Thread starter Cagey
  • Start date Start date
C

Cagey

I set vb code so a checkbox on my form enables its label to change
color once it's checked. It works on GotFocus & has worked on Lost
Focus before (not currently), but mostly I want the label to stay that
color so it's always visible for only which ever record is check marked
this way, that means first thing when the db is opened, not only after
the field is activated. Anyone?
 
Hi.

You didn't post your code, so I can't for certain tell you what to do with
it. However, the following will work.

Make sure the Back Style property of the CheckBox's label is set to Normal.
Place the following procedure in the code module of the Form (be sure to
change CheckBoxName and CheckBoxLabelName to the actual names of your
controls):

Private Sub InitCheckBox()
If Me.CheckBoxName = -1 Then
Me.CheckBoxLabelName.BackColor = 255 'Red
Else
Me.CheckBoxLabelName.BackColor = -2147483633 'Original Grey
End If
End Sub

Then, in both the Form_Current event and the CheckBox's Click event, place
the following line: InitCheckBox

If you do this, you can remove whatever code you had in the GetFocus and
LostFocus events, as it will no longer be necessary. The Form_Current event
will set the appropriate color when the form opens and every time you move to
a new record, and the Click event will do the same each time the value of the
CheckBox control changes.

-Michael
 
Thanks so much! Sounds great (like it should work)... tried it; didn't
work forgot to specify it's the color of the label text... so I
switched it to fore color instead of backcolor. Not sure what the -1
indicates? Will try again Monday; let me know if there's anything
different because it's the font color of the label instead -Thanks!!.
I'm out now until then. Have a great wknd!
 
Hi.

The value of a CheckBox is -1 when it is checked, and 0 when it is
unchecked, so the If statement is testing whether the CheckBox is checked.

As for replacing "BackColor" with "ForeColor", there's nothing different
except for the fact that you will probably want to change -2147483633 (Grey)
to 0 (Black). Otherwise, the label text will be the same color as the form,
and therefore invisible. Also, it will then not be necessary to set the Back
Style property of the CheckBox's label to Normal.

-Michael
 
Back
Top