Command Button Color Change on Mouse Button-down Action.
After working with the Command Button and Message Box Controls in MS Access, I really got bored with their styles. So, I set out to do something about it and created some animation styles for the command buttons and used Office Assistant (valid only for Access2003 and earlier versions) for Message Boxes. The Links to those Articles and free Demo Database download links are given below:
- Command Button Animation
- Command Button Animation-2
- Colorful Command Button
Message Box Styles (Access2003 or earlier versions only)
- Message Box using the Office Assistant
- MsgBox with Options Menu
- MsgBox with Checkbox Menu
Command Button Styles
Some New Trick on Command Button.
Here is a new trick for you to use on Command Button Control. Command Button will change the color on the mouse-down action and restore the original color on the mouse-up action. You can do this with a Label control that has the same dimensions as the Command Button, filled with the color you like, and position it behind the Command Button Control. You need two lines of VBA Code on the Form Module as well.
Design the New Animation Style.
Let us go through with this simple design and enjoy the new animation style of the Command Button Control.
Open a new Form.
Create a Command Button Control on the Detail Section of the Form.
Display the Command Button’s Property Sheet (F4).
Change the Name Property Value to cmdClose.
Change the Caption Property Value to Close.
Create a Label Control with some caption text near the Command Button.
Select the Command Button and the Label Control together.
Right-click it, highlight the Size option on the Shortcut Menu, and select To Tallest.
Repeat step 8 above and select To Widest.
Click on the Label Control alone and display its Property Sheet (F4).
Remove the text from the Caption property.
Change the Special Effect Property value to Raised.
Select the Back Color Property and click the Build ( . . .) button to display the Color Palette.
Select the color you like the most to fill the background of the label control.
Move the Label control behind the CommandButton control and position it completely hidden.
If the label control is above the CommandButton, then display the Shortcut Menu by right-clicking and selecting Send to Back from the Position group.
Click on the Command Button and display the property sheet (F4).
Click the Event Tab, select the Mouse Down Event, select [Event Procedure] from the drop-down list, and click the Build (. . .) button to open the Form’s VBA Module Window.
Copy and paste the following Code in the Form Module, overwriting the existing empty subroutine stubs:
Private Sub cmdClose_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) Me.cmdClose.BackStyle = 0 'transparent End Sub
Repeat step 18 for Mouse Up [Event Procedure] and copy and paste the following Code into the Form Module:
Private Sub cmdClose_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) Me.cmdClose.BackStyle = 1 'Normal End Sub
Test Run.
Now, it is time for the test run of our design.
Save the Form as frmButton.
Open frmButton in Form View.
Click the CommandButton and hold the mouse button down. You will see the CommandButton’s color change to the background fill color you selected for the label control, and the CommandButton caption text Close becomes visible on it.
Release the mouse button. The original CommandButton view is restored.
The trick works by changing the CommandButton Back Style to transparent, forcing it to display the Label control color and changes to Normal view when the mouse button is released.
You can learn another trick from an earlier Article on Transparent Command Button, here.
- Command Button Animation
- Double Action Command Button
- Colorful Command Buttons
- Transparent Command Button
- Command Button Animation-2
- Creating Animated Command Button with VBA
- Command Button Color Change on Mouse Move























