Comand button to change color

A

Access Africa

I have command buttons to open forms I want them to change color after the
client has opened the form. (Clicked on the button)
 
L

Larry Linson

I have command buttons to open forms I
want them to change color after the
client has opened the form. (Clicked on
the button)

Caveat: This is not standard Windows operation and could be confusing to
your users.

Set the Transparent property of the Command Button to "Yes". Create a
Rectangle exactly the same size, and set its BackColor to whatever you want
the color to be before the Command Button is Clicked. Then use the Color
Picker on the BackColor to choose the Color to which you'd change it. Make a
record of the values for these two colors. Position the Rectangle over the
Command Button, then use Format | Send to Back on the menu to place it
behind/below. Create a Label with the text you desire for your Command
Button and place it on top -- the Label should default to a Transparent
Background which is what you want. Now in the Click event of the Command
Button, add code to change the Color (along with whatever else you want the
button to do). Here's code to change color each time a Command Button is
clicked, from a sample database I have:

If Me.rectCommandBG.BackColor = 12632256 Then 'If grey
Me.rectCommandBG.BackColor = 12615935 'make it pink
Else
Me.rectCommandBG.BackColor = 12632256 'make it grey
End If

Or, even simpler, use a Label instead of a Command Button, set its
Background to Normal, then add code on its Click event to do whatever you'd
do in the Command Button and code to change the BackColor. The difference
will be that you can't control what the Border looks like on a Label.

Larry Linson
Microsoft Access MVP
 
V

vermutmb

Or go here: http://www.lebans.com/cmdbutton.htm

Larry said:
Caveat: This is not standard Windows operation and could be confusing to
your users.

Set the Transparent property of the Command Button to "Yes". Create a
Rectangle exactly the same size, and set its BackColor to whatever you want
the color to be before the Command Button is Clicked. Then use the Color
Picker on the BackColor to choose the Color to which you'd change it. Make a
record of the values for these two colors. Position the Rectangle over the
Command Button, then use Format | Send to Back on the menu to place it
behind/below. Create a Label with the text you desire for your Command
Button and place it on top -- the Label should default to a Transparent
Background which is what you want. Now in the Click event of the Command
Button, add code to change the Color (along with whatever else you want the
button to do). Here's code to change color each time a Command Button is
clicked, from a sample database I have:

If Me.rectCommandBG.BackColor = 12632256 Then 'If grey
Me.rectCommandBG.BackColor = 12615935 'make it pink
Else
Me.rectCommandBG.BackColor = 12632256 'make it grey
End If

Or, even simpler, use a Label instead of a Command Button, set its
Background to Normal, then add code on its Click event to do whatever you'd
do in the Command Button and code to change the BackColor. The difference
will be that you can't control what the Border looks like on a Label.

Larry Linson
Microsoft Access MVP
 
Top