Introduction.
We have seen the Double-Action Command Button in an earlier Post and Command Button Animation before, and now it is time to add some color to the Command Buttons. Take a look at some different Command Buttons in action on a Control Screen (Main Switchboard) of a sample MS-Access Application.
Would you like to use these colorful buttons in your own application?
You might be expecting a long lecture from me about their setup — maybe a hundred lines of VBA code tucked away at the end of this article for you to copy and paste. Or perhaps you’re bracing yourself to download some MS Access add-ons, link a couple of library files, and wrestle with complex installations.
Well… none of that is needed.
In fact, you can create one of these buttons in just two minutes — maybe three the first time you try. Once you’ve made one, you can produce variations in under a minute.
Here’s the twist: these buttons are not created inside MS Access at all. Instead, we make them in MS Word (or Excel, if you prefer), then copy and paste them straight into an Access form. After that, just tweak a few settings in the Property Sheet, add maybe one or two lines of VBA for animation, and you’re ready to roll.
Designing the Button.
Open your MS Access project and open a form in Design View.
-
Launch MS Word and check whether the Drawing Toolbar is visible at the bottom, just above the status bar.
-
If it’s not visible, go to View → Toolbars → Drawing.
-
If the Drawing Toolbar button is already visible, then click it to display the toolbar.
-
-
On the Drawing Toolbar, click AutoShapes → Basic Shapes → Rounded Rectangle.
Draw a Rounded Rectangle on the Word document.
-
Right-click the shape you just created and choose Format AutoShape from the shortcut menu.
-
In the Format AutoShape dialog box, go to the Colors and Lines tab.
-
Under the Fill group, open the Color drop-down list to select your preferred fill color.
Click on the Yellow color on the Color Palette, and then click on the Fill Effects. Control.
In the Fill Effects dialog box, select the Gradient tab.
-
Under Shading Styles, choose Vertical.
-
In the Variants section, click the shape at the bottom right corner.
-
The selected gradient will appear under the Sample preview on the right.
-
-
Click OK, and then click OK again in the Format AutoShape dialog to apply the chosen gradient to the Rounded Rectangle.
-
Right-click the shape and select Edit Text from the shortcut menu.
-
Type the button caption—for example, Data Files. Highlight the text and apply the desired formatting using Word’s standard tools:
-
Align Center
-
Bold
-
A font color that provides good visibility against the gradient background.
-
Note: Once you copy and paste the button into an MS Access form, you cannot change its caption or formatting there. It’s a good practice to keep a copy of the original buttons in the Word document. If you need changes later, edit them in Word, then copy and paste the updated version into Access.
You can make copies of this Button and follow from Step 5 above to change the Gradient Color and Caption according to your needs.
Tips: You can easily change the shape of your created buttons:
-
On the Drawing toolbar in Word, open the Draw menu.
-
Select Change AutoShape, then choose any shape you prefer for your button.
To insert the button into Access:
Right-click the button in Word and choose Copy from the shortcut menu.
Minimize Word and return to the Access form you have open in Design View.
Right-click in the form’s Detail or Footer section where you want the button placed, and choose Paste.
Drag and position the button to the desired location.
Adjusting the button display in Access:
Right-click the pasted button in Access and select Properties.
Move the Property Sheet so it does not overlap the button.
Locate the Size Mode property and experiment with the available settings:
-
Clip
-
Zoom
-
Stretch
-
When Zoom is selected, the button resizes proportionally, maintaining the height-to-width ratios. However, it may leave a gap around the image. You can fill this background area with the Form’s background color so the gap is not visible when the form opens in Normal View.
-
If the button is in the Footer Section of your Form, then click on the Footer Section of the Form to select it and display the Property Sheet.
Copy the Back Color Property Value of the Form.
Click on the button to display the Property Sheet of the Button.
Paste the value in the Back Color property copied from the Form.
Change the Special Effect Property to Raised.
Change the Border Style Property to Transparent.
Now you can program your Colorful Command Button like a normal MS-Access Command Button.
If you look at the Property Sheet of this Command Button, you can see that all the essential Properties and Events are available for Event Procedures, Hyperlinks, Macros, etc.
I will give you one line of Code to put some life (Animation) into this Button so that it will respond when the mouse moves over it.
Click on the Button's Mouse Move Property and select Event Procedure. Copy the following Code between the Empty Subroutine lines.
Me.OLEUnbound257.SpecialEffect = 2
Copy the correct name of the Button from its Name Property and paste it to replace OLEUnbound257. Mind the dot separator after the word Me. And at the beginning of SpecialEffect, while pasting the Button Name.
Select the Form's Section (Detail or Footer, or Header) where you have placed the Command Button and display the Property Sheet.
Click on the Mouse Move Property and select Event Procedure, copy and paste the above line of Code with the Button Name change, and paste between the empty Subroutine lines.
Change the Value 2 to 1.
- Command Button Animation
- Double-Action Command Button
- Colorful Command Buttons
- Transparent Command Button
- Command Button Animation-2
- Creating an Animated Command Button with VBA
- Command Button Color Change on Mouse Move
Animating the Button.
Initially, the Button will be in a Raised Style. When the mouse is moved over the Button, then it will be pushed in (Sunken). When the Mouse is moved out of the Button, it will restore to the raised state. If you repeat this action in quick succession, the Animation will be more evident.
We will learn some more tricks with Command Buttons.
What do you think about them?
it does work,
ReplyDeletehowever:
- pls open windows task manager, then click performance tab.
- then go back to the form containing those buttons
- pls drag the mouse-pointer over the form again and again..
- see on windows task manager, u will notice that the CPU usage is getting higher...
because ms access always proceed "on move event" everytime we drag the mouse over the form...
regards
a SAP Lover
romy
Yes it does work,
ReplyDeletehowever, pls do the following steps:
- pls open windows task manager, then click performance tab.
- then go back to the form containing those buttons
- then pls drag the mouse over the form again and again..
- see on windows task manager, u will notice that the CPU usage is getting higher...
because ms access always proceed "on move event" everytime we drag the mouse over the form...
regards
a SAP Lover
Yes, you have a point there. But the Mouse Movements are always monitored by the system and a certain level of increase in CPU usage also noticed when the Mouse is in motion elsewhere.
ReplyDeleteThe statement in question (
Me.OLEUnbound257.SpecialEffect = 2) can be put in test and prevent it from setting the value repeatedly when the value is already set, which will reduce the activity to a certain degree, like:
If
Me.OLEUnbound257.SpecialEffect = 2 then
Me.OLEUnbound257.SpecialEffect = 1
End If
I like the ability to add buttons with color to my Access forms. I have noticed one drawback, however, possibly because I have done something wrong.
ReplyDeleteWhen colored buttons are created using the Copy/Paste from Word, the buttons on the Access form do not appear in the Tab Sequence. When I run the form in form view, I cannot tab to the buttons, nor can I "click" them using the spacebar or enter key like I can for normal buttons. This is a drawback to my GUI, which is very keyboard intensive.
Have I done something wrong, or is this the correct functionality?
Thanks
GRC
This is a known issue that it doesn't have the Tab Order Property. You have done nothing wrong. As an alternative measure you can create a Transparent Command Button (http://www.msaccesstips.com/2008/04/transparent-command-button/) with the same size and place it over the Colorful Comand Button and then you can set the tab order property value of the transparent command button. When you set the Transparent Property of a Normal Command Button to Yes; it becomes transparent or invisible.
ReplyDeleteRegards,
a.p.r. pillai