Solved Change Label Color of Field Form based on value (1 Viewer)

kengooch

Member
Local time
Today, 13:12
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:

Ranman256

Well-known member
Local time
Today, 16:12
Joined
Apr 9, 2015
Messages
4,339
You can set this in CONDITIONAL FORMATTING, thus remove the need to write code.
 

kengooch

Member
Local time
Today, 13:12
Joined
Feb 29, 2012
Messages
137
Thanks for the thought, but Conditional Formatting doesn't work with a check box
 

Gasman

Enthusiastic Amateur
Local time
Today, 20:12
Joined
Sep 21, 2011
Messages
14,047
Check that the BackStyle is Normal and not Transparent.
 

Isaac

Lifelong Learner
Local time
Today, 13:12
Joined
Mar 14, 2017
Messages
8,738
Is BeforeUpdate the correct event to use for this? I would normally use After update ...
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 20:12
Joined
Jul 9, 2003
Messages
16,245
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_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 15:12
Joined
Feb 28, 2001
Messages
27,001
The one I always used was "LostFocus" as a time to verify that the control's color was correct.
 

deletedT

Guest
Local time
Today, 20:12
Joined
Feb 2, 2019
Messages
1,218
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

  • Database8.accdb
    388 KB · Views: 155

Gasman

Enthusiastic Amateur
Local time
Today, 20:12
Joined
Sep 21, 2011
Messages
14,047
The BeforeUpdate and Onclick event both worked for me, but only after changing the BackStyle property?
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 20:12
Joined
Jul 9, 2003
Messages
16,245
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

Top Bottom