Building Access form is a time consuming aspect to front-end database designs and in this Microsoft Access tutorial, I want to add some extra aesthetics and alternative control enhancements for you.
There are many Access form controls, formats and properties that can be applied to a form over and above the basics ranging from the more advanced conditional formatting options to the custom built controls including my recent post on coloured tab controls.
So here’s some alternatives for your traditional command button…
Using the standard command button, you can still apply different format effects using the correct event with some Access VBA code or adopt a different control altogether (i.e. a Label) and make this your button click action instead.
Hyperlinks are also another way to apply actions for opening another form or running a report and can exclude VBA code (for basic actions).
Microsoft Access Tutorial: How To Build Alternative Access Form Controls – The Command Button
Let’s work on and illustrate the alternative button option using a Label and some VBA code. Take a look at the following screenshot:
When you hover over an item in the dark blue banner, the item turns a subtle white from the resting light blue resetting all other menu items including the ‘Close‘ item.
Of course, you can set any format by adding a raise, sunken effect or enhancing with underline, bold, change the background or changing font sizes – it’s how creative do you want to be?
I used a Label control and set the default to a non-selected state. In this example, I used the following:
- Set the Caption property as you may want to change the caption from say ‘On‘ to ‘Off‘.
- Back Style property to ‘Normal‘
- Back Color property to ‘#003366‘ which reflects the dark blue banner colour though could be set as transparent.
- Border Style property set to ‘Transparent‘.
- Border Width property set to ‘Hairline‘.
- Border Color property set to ‘No Color‘.
- Special Effect property set to ‘Flat‘.
- Fore Color property set to ‘#7DBEDC‘ (which is light blue colour).
You may want to look at my eBook on How to Build Access Database Forms for more detailed explanation on the above properties and general design techniques for your forms.
I would suggest you also apply some consistency to the names for your Labels that will be acting as a button as you could be clever to group and loop your Access VBA code more effectively. You could also adopt the Tag property to help separate this type of control use with others.
What about the VBA code?
Well, you will probably want a public procedure to reset all controls and individually apply format changes to the selected item.
Therefore, using the main event called ‘On Mouse Move‘ would be advisable. You will still need to add code the ‘On Click‘ event so when users click the item it will execute the action of opening a form or report or whatever it is your want to action (which has been excluded in this article).
I created a public sub procedure called ResetMenuLabels that runs the following code:
(Please ignore the word ‘Private’ in the above code snippet. It should be ‘Public’ as it should really be stored in a module (which this example doesn’t use) making this available to any form).
The above code will loop through all controls for your form but only check to first the active control is a Label type and that is had the Tag set as ‘lb‘ (standing for Label Button). Providing you don’t use this convention for any other control, you are pretty safe for this form to reset all label buttons back to the resting style.
I’ve only used a simple format here for illustrative purposes and of course would expect you take it to the next step and apply your chosen styles – simple fill in between the loop structure.
The added element now is to call this procedure for the individual control’s ‘On Mouse Move‘ event with the additions for highlighting this control standing out from all others.
Here’s an example for the ‘Close‘ button label:
So now this Microsoft Access tutorial on how to use alternative buttons opens the mind a little further.
The downside unfortunately is this will add to the time consuming task for your Access form designs!
I would love to hear from you perfectionists out there on what alternative buttons you have adopted for you Access forms in the reply box below.
Tags: access database design, access form designs, access vba code, how to build a command button in ms access, microsoft access tutorial