Does this "blue" have a code? (1 Viewer)

Big Pat

Registered User.
Local time
Today, 13:57
Joined
Sep 29, 2004
Messages
555
Where can I find the Hex or RGB value for the blue colour that Access 2010 uses by default for buttons on forms? I need to change some buttons to yellow (I know the code for that) but later change them back to the previous shade of blue, which is shown in the Properties pane "Accent 1, Lighter 40%".

By clicking in the standard colors area at the bottom of the colour chooser I can find a very similar blue #D6DFEC but it doesn't look quite right. And the "accent" colour does not give me a Hex value.

Is that "usual" blue even one colour? Now that I look carefully it seems to be a graduated colour, slightly lighter at the top. How can I reset a button to that style having changed it?

Thanks
 

vbaInet

AWF VIP
Local time
Today, 13:57
Joined
Jan 22, 2010
Messages
26,374
Debug.Print the Backcolor of the section and you'll get the Long Integer number.
 

Big Pat

Registered User.
Local time
Today, 13:57
Joined
Sep 29, 2004
Messages
555
Sorry - I may have given the impression I know what I'm doing. I don't!!

I believe I need to press Ctrl+ G and then type Debug.Print....something???

What's the syntax? The name of the button is cmdCurrent

Thanks
 

vbaInet

AWF VIP
Local time
Today, 13:57
Joined
Jan 22, 2010
Messages
26,374
Run this in the click event of a button on the form:
Code:
Debug.Print Me.Section(acHeader).BackColor
.. then look in the Immediate Window (Ctrl+G).
 

Big Pat

Registered User.
Local time
Today, 13:57
Joined
Sep 29, 2004
Messages
555
That results in an error message.

"Run-time error 2462. The section number you entered is invalid."
 

vbaInet

AWF VIP
Local time
Today, 13:57
Joined
Jan 22, 2010
Messages
26,374
What control/section colour are you trying to get?
 

Big Pat

Registered User.
Local time
Today, 13:57
Joined
Sep 29, 2004
Messages
555
I'm trying to get the colour of the button itself which is called cmdCurrent.

I have three buttons that switch between different views of data and I want the currently active button to be yellow. So I have code like this:

Code:
'Change the colours of the buttons
Me.cmdPreValid.BackColor = RGB(255, 242, 0)     'yellow
Me.cmdCurrent.BackColor = RGB(214, 223, 236)    'blue
Me.cmdCompleted.BackColor = RGB(214, 223, 236)  'blue

and the plan is to have similar code on each button, just switchinig the blue and yellow codes around as needed. But that's not the right blue. It's close, so I can certainly live with it, but I'm just curious how I can make the button go back to the "theme" colour which is labelled as Accent 1, Lighter 40% but seems to have no hex value.

Thanks for your help.
 

vbaInet

AWF VIP
Local time
Today, 13:57
Joined
Jan 22, 2010
Messages
26,374
Use the same code to get the backcolor of the button.
 

vbaInet

AWF VIP
Local time
Today, 13:57
Joined
Jan 22, 2010
Messages
26,374
Extra info: If you want to revert the colour back to its original state then save it in a Long variable before changing it. You can then use the value from the variable to set it back.
 

Big Pat

Registered User.
Local time
Today, 13:57
Joined
Sep 29, 2004
Messages
555
Use the same code to get the backcolor of the button.

Um... I think I did. The code for the OnClick event of one of the buttons is now as follows:

Code:
Private Sub cmdPreValid_Click()

'Show the pre-valid subform and hide the other two
'Me.frm01_PreValid.Visible = True
'Me.frm01_PreValid.Requery            'make sure it has the latest data
'Me.frm02_Current.Visible = False
'Me.frm03_Completed.Visible = False

'Change the colours of the buttons
'Me.cmdPreValid.BackColor = RGB(255, 242, 0)     'yellow
'Me.cmdCurrent.BackColor = RGB(214, 223, 236)    'blue
'Me.cmdCompleted.BackColor = RGB(214, 223, 236)  'blue


Debug.Print Me.Section(acHeader).BackColor


End Sub

I commented out everything else so that only the Debug.Print line would run and as soon as I click ed the button I got that error message,
 

vbaInet

AWF VIP
Local time
Today, 13:57
Joined
Jan 22, 2010
Messages
26,374
Focus on this comment more Big Pat.
Extra info: If you want to revert the colour back to its original state then save it in a Long variable before changing it. You can then use the value from the variable to set it back.
 

Brianwarnock

Retired
Local time
Today, 13:57
Joined
Jun 2, 2003
Messages
12,701
Hi vba
Do you do that by

Dim origcolour as long

Origcolour = me.cmdcurrent.backcolor

Brian
 

vbaInet

AWF VIP
Local time
Today, 13:57
Joined
Jan 22, 2010
Messages
26,374
That's it Brian!
So Big Pat just needs to declare Private variables in the Declarations section (i.e. below Options Compare Database and Options Explicit) and in the Open event of the form save the colour values to the variables.
 

Brianwarnock

Retired
Local time
Today, 13:57
Joined
Jun 2, 2003
Messages
12,701
Cheerios folks time for this old guy to go sleep off the vino.

Brian
 

Brianwarnock

Retired
Local time
Today, 13:57
Joined
Jun 2, 2003
Messages
12,701
Having had my morning shot of caffeine can I add that I have never messed with colours in Access so was just checking that it was the same as in Excel, I expected it to be so.
I had to do a lot with colours in a couple of Workbooks and what I did was declare public variables mylightred mydarkred myblue etc
These were much simpler to use than quoting the RGB or long value each time and self documenting of course.

Brian
 

vbaInet

AWF VIP
Local time
Today, 13:57
Joined
Jan 22, 2010
Messages
26,374
I was thinking you would be on herbal tea instead!
Yes, they're pretty much the same. The Long Integers are simple and convenient to use, no faffing with RGB or Hex... it's not a colour palette application we're building.
 

Big Pat

Registered User.
Local time
Today, 13:57
Joined
Sep 29, 2004
Messages
555
Sorry guys, I had evidently strayed into far deeper waters than I'd thought. I don't wish to appear ungrateful, as I have learned almost everything I know about Access from this site, often from you two, but on this occasion I'm going to just use the blue I know the code for.

"Declare private variables in the Declarations section..." I'd have to spend some time reading/googling/figuring out what that even means and unfortunately the pressure is on.

Plus...I need to get a life and stop working nights and weekends, there's been far too much of that recently.

Thanks. I really DO appreciate your help and no doubt I'll be back before long when i get stuck on something else :)
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 13:57
Joined
Sep 12, 2006
Messages
15,659
just to confirm.

the colour code you see in a property sheet is a longint

RGB takes 3 single byte values in the range 0-255 to produce the value.

either R*65536 +G*256 +B
(or B*65536 +G*256 +R) I forget which offhand and I always have to look it up.

so you can directly use a long int number, or use RGB(r,g,b) to generate the long int. Analysing a number to produce the RGB components is a bit trickier, and needs a bit of VBA

now some property values show as large values which are not in the range of a longint. In this case, you are seeing values that correspond with SETTINGS as per the WINDOWS THEME, rather than colours directly.

miserably, VBA only provides 8 constants, corresponding to the 8 binary selections between 0 and 255 for each of the RGB components. Shame they don't have more. so eg vbmagenta is RGB(255,0,255) (red+blue), yellow is red+green and cyan is blue+green
 

Users who are viewing this thread

Top Bottom