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

kengooch

Member
Local time
Today, 10:45
Joined
Feb 29, 2012
Messages
30
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

Registered User.
Local time
Today, 13:45
Joined
Apr 9, 2015
Messages
3,766
You can set this in CONDITIONAL FORMATTING, thus remove the need to write code.
 

kengooch

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

Gasman

Enthusiastic Amateur
Local time
Today, 18:45
Joined
Sep 21, 2011
Messages
7,727
Check that the BackStyle is Normal and not Transparent.
 

Isaac

Lifelong Learner
Local time
Today, 10:45
Joined
Mar 14, 2017
Messages
3,748
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, 18:45
Joined
Jul 9, 2003
Messages
12,447
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, 12:45
Joined
Feb 28, 2001
Messages
19,035
The one I always used was "LostFocus" as a time to verify that the control's color was correct.
 

deletedT

Guest
Local time
Today, 18:45
Joined
Feb 2, 2019
Messages
1,220
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: 22

Gasman

Enthusiastic Amateur
Local time
Today, 18:45
Joined
Sep 21, 2011
Messages
7,727
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, 18:45
Joined
Jul 9, 2003
Messages
12,447
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