Back color code for a command button

accessfever

Registered User.
Local time
Yesterday, 20:20
Joined
Feb 7, 2010
Messages
101
I created 4 command boxes, 1 list box, 2 textboxs and 1 combo box in a form. I wanted all boxes have the same look like the command box. However, I tried different grey colors but still could match the command box's back color. Would someone know the exact back color code for a command box?
 
The "BackColor" property for Command Buttons doesn't exist in the Properties list. An attempt to address it via VBA results in the following: Run-time error '438': Object doesn't support this property or method.

If you want to create a Command Button similar to those created by the Command Button WIZARD you'll have to make your own from a rectangle, then you can color it any backcolor you want. Use the Special Effect: Raised, then select any Back-Fill Color.

You can add your event to the ON_CLICK property and it will work just like the buttons you can create from the wizard.

If you have a problem with the code then create your wizard button and copy the resulting code from VBA Editor by examining the ON_CLICK property of that button. Once you have the code copied, you'll paste it into the same ON_CLICK property for the "FANCY" button you've created, but be sure to adjust the name references to the button so that it works seamlessly.

Good Luck!
Goh
 
Last edited:
It worked. Thanks very much!
 
You're welcome.
I addition to this I found that you can make the button automated like the wizard does by adding thes two commands to the MOUSEDOWN and MOUSEUP events for the button.

Private Sub YOURRECTANGEBOXNAME_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
'Format Sunken
Forms("YOUR MAIN FORM").Controls("YOUR SUBFORM IF YOU HAVE ONE").Controls("YOUR RECTANGLE BOX NAME").SpecialEffect = 2
End Sub

Private Sub YOURRECTANGEBOX_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
'Format Back to Raised
Forms("YOUR MAIN FORM").Controls("YOUR SUBFORM IF YOU HAVE ONE").Controls("YOUR RECTANGLE BOX NAME").SpecialEffect = 1
End Sub

Cheers!
Goh

I just added to this because I'll probably want to look it up myself later LOL
 
Goh's solved your question by reversing it, not changing the Textbox Back Color to match your Command Button, but just the opposite, matching the Command Button to the Textbox! This approach is necessary if you want to control the Command Button's Back Color, but to match the color of any Windows-determined object, such as a Command Button, you simply have to use the Windows ColorIDs! For Command Button Back Color that would be

-2147483648

and notice the minus sign in front of the code; it's necessary!

I use these codes so that the colors of my apps match the colors chosen by a given user, for his PC through the Windows Control Box. Here's the entire list:


Color ID... Color Description
----------- -----------------
-2147483648 Scroll bar, Button Back Color
-2147483647 Desktop
-2147483646 Active window title bar
-2147483645 Inactive window title bar
-2147483644 Menu bar
-2147483643 Window
-2147483642 Window frame
-2147483641 Menu Text
-2147483640 Window Text
-2147483639 Title bar text
-2147483638 Active window border
-2147483637 Inactive window border
-2147483636 Application background
-2147483635 Highlight
-2147483634 Highlight Text
-2147483633 3-D face
-2147483632 3-D shadow
-2147483631 Dimmed (disabled) text
-2147483630 Button Text
-2147483629 Inactive window title bar text
-2147483628 3-D highlight
-2147483627 3-D dark shadow
-2147483626 3-D light
-2147483625 ToolTip Text
-2147483624 ToolTip background
-2147483621 Active window title bar color2

Linq ;0)>
 
awesome. I used the color of "system button face" and it worked. Thanks!
 
It's a handy table of IDs to know about.

Glad we could help!

Linq ;0)>
 

Users who are viewing this thread

Back
Top Bottom