Introduction.
After working with the Command Button and Message Box Controls of 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 downloads links are given below:
- Command Button Animation
- Command Button Animation-2
- Colorful Command Button
Message Box Styles (Access2003 or earlier versions only)
- Message Box with 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 button down the action and will restore the original color on the mouse-up action. You can do this with a Label control, with the same dimension as the Command Button, filled with the color you like, and by placing 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 on it and 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 on the Build ( . . .) button to display the Color Palette.
Select the color you like to fill the background of the label control.
Move the Label control behind the Command Button control and place it completely hidden.
If the label control is overlapping the Command Button then display the Shortcut Menu by right-clicking on it and selecting Send to Back from the Position group.
Click on the Command Button and display the property sheet (F4).
Click on the Event Tab and select the Mouse down Event, select [Event Procedure] from the drop-down control and click on the build (. . .) button to open the Form’s VBA Module Window.
Copy and Paste the following Code into the Form Module, over-writing the existing two empty lines that appeared there:
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 with the name frmButton.
Open frmButton in Form View.
Click on the Command Button and hold the mouse button down. You will see the Command Button’s Color changes to the background fill color you have selected for the label control and Command Button caption-text Close appearing on it.
Release the mouse button. The original state of the Command Button is restored.
The trick works by changing the Back Style of the Command button to transparent, forcing it to display the color of the Label control behind it and changing to a 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