Solved Change Label Color of Field Form based on value

kengooch

Member
Local time
Yesterday, 18:36
Joined
Feb 29, 2012
Messages
137
I have a form with a check box named [tConcur] If the user clicks the checkbox on, I want the label of the check box to change to Green.
this is what I tried, but it doesn't work.

Code:
Private Sub tConcur_BeforeUpdate(Cancel As Integer)
If (tConcur = -1) Then
Me!LConc.BackColor = vbGreen
Else
LConc.BackColor = RGB(239, 211, 210)
End If
End Sub
 
Last edited by a moderator:
You can set this in CONDITIONAL FORMATTING, thus remove the need to write code.
 
Thanks for the thought, but Conditional Formatting doesn't work with a check box
 
Is BeforeUpdate the correct event to use for this? I would normally use After update ...
 
I think Paul has hit the nail on the head! I recall having a similar problem with an Option Group. I couldn't work out why the colour of the label wouldn't change? I blogged about it on my website here:-

Option Group Label Color Change

There's a YouTube video explaining the issue.
AND
There's a sample file available. To get it for free, use Coupon Code:- 6p7nqrv
 
The one I always used was "LostFocus" as a time to verify that the control's color was correct.
 
I think Paul has hit the nail on the head! I recall having a similar problem with an Option Group. I couldn't work out why the colour of the label wouldn't change? I blogged about it on my website here:-

Option Group Label Color Change

There's a YouTube video explaining the issue.
AND
There's a sample file available. To get it for free, use Coupon Code:- 6p7nqrv
For me BeforeUpdate changes the backcolor.
 

Attachments

The BeforeUpdate and Onclick event both worked for me, but only after changing the BackStyle property?
 
I think I have confused the issue in this thread. I referred to Gasman as Paul without being clear as to who I was referring to.

Gasman originally said:-

Check that the BackStyle is Normal and not Transparent.

And I replied:-

I think Paul has hit the nail on the head! (Gasman)

The label colour is changing, but you can't see it because the label BackStyle is set to transparent by default.

Remedy this and the colour change will become apparent.
 

Users who are viewing this thread

Back
Top Bottom