How to unselect radio buttons in MS Access after it has been selected
Radio buttons are useful MS Access user interface control element in Access Forms design. It is useful in that there is only one radio button can be selected at any time. So when you need the user to select only one choice from a group of options, use radio button. To create a group of radio buttons in Access, use the Option Group control.
The problem with Option Group radio buttons is that, once the user selected one radio button, it can't be deselected or unselected. Sometimes your application may require that none of these radio buttons should be selected. In this case, you need an easy way to let the user quickly unselect the selected radio button.
The way to solve this problem is add one line of VBA code to the double click event of the radio button control.
Below is a demo on how to unselect radio button in Access. We will create a group of three radio buttons - Egg, Milk, Bread. After finish, you should be able to select a radio button and if you double click the selected radio button, it's unselected.
Here are the steps to create a tiny VBA code for the On Dbl Click (on double click) event to deselect a radio button group.
Step #1: Create a new form in your Access database.
Open an empty Access application. On the left hand side menu, click Forms and then click New button.
Step #2: Add a new Option Group control on this form.
Select Option Group from within the Toolbox panel.
Step #3: Add three labels to the Option Group.
Click anywhere on the new form and Option Group Wizard is opened. Type in three label names (Egg, Milk, Bread). Click Finish to complete.
The newly created Option Group looks like this:
Step #4: Open the control's Properties window and select Event tab.
Click the line surrounding the group and select Properties in the pop-up menu. Then click Event tab when the properties window comes up.
Step #5: Select anywhere inside "On Dbl Click" event.
Click the button that has ... in it.
Step #6: Select Code Builder to open VBA editor.
This will open VBA code editor so you can add code in it.
Step #7: Add the following code to the sub routine.
Add the following line of code into the double click event sub-routine.
Me.Frame0 = ""
This is how it looks like in VBA code editor:
Step #8: View the form in Form View.
Save the VBA code and then go back the forms Design View and change it to Form View. Now select a radio button such as Egg.
Step #9: Double click any radio button to unselect them.
Now to unselect the radio button you have just selected, double click any radio button and the selection is dimmed, which means no radio button is selected.
Hope you enjoy this simple but very useful tip in Access form design.
Copyright © 2016 GeeksEngine.com. All Rights Reserved.
This website is hosted by LunarPages.
No portion may be reproduced without my written permission. Software and hardware names mentioned on this site are registered trademarks of their respective companies. Should any right be infringed, it is totally unintentional. Drop me an email and I will promptly and gladly rectify it.