Version 1.3 Approx 0.4 MB (zipped) First Published 23 May 2022 Last Updated 24 Jan 2026
UPDATED 24 Jan 2026 : new version with slightly modified code
The form/report controls available in Access have been around for over 20 years with only minimal change.
There is a real need for new controls to be added that don’t depend on the use of ActiveX
This is the first in an occasional series of additional controls that can be added to Access forms without requiring ActiveX functionality
It is based on a thread I posted at Access World Forums in Dec 2017, Toggle On/Off Button where I asked:
Does anyone know of a form control which can act in a similar way to those below?
This type of control is common in Windows settings and on smartphones but is not available in Access.
Fellow forum member, Chris Arnold, suggested a simple solution:
You can use a button - use format to select a quick style, but you would need code to set border, back and fore colors - plus code to change the alignment.
Use Wingdings font (lowercase L) or Webdings (lowercase N)
The prompt acted as a reminder about using Quick Styles and other items on the Control Formatting section of the Format ribbon:
Quick Styles:
Change Shape:
Shape Effects:
It took no more than 2 minutes to achieve exactly what I wanted!
In this case I just needed to use Change Shape to create the rounded corners effect and code to toggle the appearance of each button.
In the latest version (1.3), I used a custom color ColBlue with the value RGB(0,114,195) as a close approximation to that in Windows Settings.
|
|
After creating the rounded button(s), add the button caption as a lower case 'l' in Wingdings then add code similar to this to your form module.
CODE:
Option Compare DatabaseOption ExplicitConstColBlueAs Long= 12808704'RGB(0,114,195)'---------------------------------Private Subcmd1_Click()If Me.lbl1.Caption= "On"ThenFormatButtonFalse,cmd1FormatButtonTrue,cmd2Me.lbl1.Caption= "Off"Me.lbl2.Caption= "On"ElseFormatButtonTrue,cmd1FormatButtonFalse,cmd2Me.lbl1.Caption= "On"Me.lbl2.Caption= "Off"End IfEnd Sub'------------------------------------Private Subcmd2_Click()If Me.lbl2.Caption= "On"ThenFormatButtonFalse,cmd2FormatButtonTrue,cmd1Me.lbl1.Caption= "On"Me.lbl2.Caption= "Off"ElseFormatButtonTrue,cmd2FormatButtonFalse,cmd1Me.lbl1.Caption= "Off"Me.lbl2.Caption= "On"End IfEnd Sub'------------------------------------FunctionFormatButton(IsOnAs Boolean,ctrlAscontrol)'sets the toggle button appearance on/offIfIsOnThenctrl.BorderColor=ColBluectrl.BackColor=ColBluectrl.ForeColor=vbWhitectrl.Alignment= 3Elsectrl.BorderColor=vbBlackctrl.BackColor=vbWhitectrl.ForeColor=vbBlackctrl.Alignment= 0End IfEnd Function'------------------------------------Private SubForm_Load()'set cmd1 button 'on' and cmd2 'off'Me.lbl1.Caption= "Off"cmd1_ClickEnd Sub
Download
Click to download: OnOffToggle_v1.3.zip Approx 0.4 MB (zipped)
Related Article
See also my latest article on this ideawhich also includes a practical example app: Settings Form with On/Off Toggle Slider Controls
The article also includes several links to alternative solutions created by other developers.
Feedback
Please use the E-Mail button in the contact form below to let me know whether you found this article useful or if you have any questions.
Please also consider making a donation towards the costs of maintaining this website. Thank you
Colin Riddington Mendip Data Systems Last Updated 24 Jan 2026
Return to Code Samples Page
Return to Top