Solved Make button specific backcolor (1 Viewer)

kenrav

New member
Local time
Today, 05:58
Joined
Jun 20, 2020
Messages
29
I need to change the default backcolor of a button to #22B14C when clicked. How can I do this?

Thanks!

kenrav
 

theDBguy

I’m here to help
Staff member
Local time
Today, 05:58
Joined
Oct 29, 2018
Messages
21,477
Have you tried assigning that value in the Pressed Color property?

PS. The color will only change as long as the user is clicking on the button. As soon as they are done clicking (released the mouse button), then the color will change back.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 07:58
Joined
Feb 28, 2001
Messages
27,194
I was surprised at TheDBGuy's answer. Doing a little bit of form and web research, I noted some discussion regarding that older versions of Access have command buttons that do not support the .BackColor property and are controlled by the Windows chosen STYLE. Therefore, @kenrav please tell us what version of Access you want to use because the answer might be different based on the version in question.

In Ac2010 I have command buttons that have an "ordinary" .BackColor property and that can change persistent color in response to VBA code. Just a matter of the OnClick event for that control with some VBA to assign the .BackColor value. The more significant question is whether that color choice should be changed again later if some other conditions change. Let us know the rules for ALL of that control's color changes so we can give best advice for the problem as a whole.
 

kenrav

New member
Local time
Today, 05:58
Joined
Jun 20, 2020
Messages
29
Have you tried assigning that value in the Pressed Color property?

PS. The color will only change as long as the user is clicking on the button. As soon as they are done clicking (released the mouse button), then the color will change back.
Actually, no (although I'm sure your solution would work.) In my scenario, when the button is clicked, I need to first check a couple of things in my SQL database before giving it the OK to change color. (I should have mentioned this in my question.)

I appreciate your help!

kenrav
 

kenrav

New member
Local time
Today, 05:58
Joined
Jun 20, 2020
Messages
29
I was surprised at TheDBGuy's answer. Doing a little bit of form and web research, I noted some discussion regarding that older versions of Access have command buttons that do not support the .BackColor property and are controlled by the Windows chosen STYLE. Therefore, @kenrav please tell us what version of Access you want to use because the answer might be different based on the version in question.

In Ac2010 I have command buttons that have an "ordinary" .BackColor property and that can change persistent color in response to VBA code. Just a matter of the OnClick event for that control with some VBA to assign the .BackColor value. The more significant question is whether that color choice should be changed again later if some other conditions change. Let us know the rules for ALL of that control's color changes so we can give best advice for the problem as a whole.
Yes, I should have provided more info.

I'm using the latest subscription version of Microsoft 365. After the click, my vba code checks a couple of things in my connected SQL database. If all good, I'd like the backcolor to change to that specific shade of green. If not, the backcolor remains the same.

I can do "Me.ComScanAuth.BackColor = vbGreen" but I'd really like it to be a slightly different shade of green (#22B14C), if possible.

kenrav
 

plog

Banishment Pending
Local time
Today, 07:58
Joined
May 11, 2011
Messages
11,648
In my scenario, when the button is clicked

Assuming your buttons control name is 'ButtonName' this is the code you add its OnClick event:

Code:
Private Sub ButtonName_Click()
  ' change button color to #22B14C  when clicked
 
ButtonName.BackColor = RGB(34, 177, 76)
ButtonName.HoverColor = RGB(34, 177, 76)

End Sub

If its conditional on something, perform that test and put it in an IIF
 

kenrav

New member
Local time
Today, 05:58
Joined
Jun 20, 2020
Messages
29
Assuming your buttons control name is 'ButtonName' this is the code you add its OnClick event:

Code:
Private Sub ButtonName_Click()
  ' change button color to #22B14C  when clicked

ButtonName.BackColor = RGB(34, 177, 76)
ButtonName.HoverColor = RGB(34, 177, 76)

End Sub

If its conditional on something, perform that test and put it in an IIF
Perfect! Thanks! Which Hex to RGB converter did you use?
 

theDBguy

I’m here to help
Staff member
Local time
Today, 05:58
Joined
Oct 29, 2018
Messages
21,477
Perfect! Thanks! Which Hex to RGB converter did you use?
When I said try assigning that value to the property, this was more like what I had in mind.
Code:
Me.ButtonName.BackColor = &H22B14C
Cheers!
 
Last edited:

plog

Banishment Pending
Local time
Today, 07:58
Joined
May 11, 2011
Messages
11,648
Which Hex to RGB converter did you use?

My casio calculator. I'm sure typing 'hex X to decimal ' into Google will do it to.

Like
 

Users who are viewing this thread

Top Bottom