Code Samples for Businesses, Schools & Developers

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?

ToggleOnOff
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:

ControlFormat
Quick Styles:

QuickStyles

Change Shape:

ChangeShape

Shape Effects:

ShapeEffects

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.

image1 image2


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 Database
Option Explicit

Const ColBlue As Long = 12808704 'RGB(0,114,195)

'---------------------------------

Private Sub cmd1_Click()

If Me.lbl1.Caption = "On" Then
FormatButton False, cmd1
FormatButton True, cmd2
Me.lbl1.Caption = "Off"
Me.lbl2.Caption = "On"
Else
FormatButton True, cmd1
FormatButton False, cmd2
Me.lbl1.Caption = "On"
Me.lbl2.Caption = "Off"
End If

End Sub

'------------------------------------

Private Sub cmd2_Click()

If Me.lbl2.Caption = "On" Then
FormatButton False, cmd2
FormatButton True, cmd1
Me.lbl1.Caption = "On"
Me.lbl2.Caption = "Off"
Else
FormatButton True, cmd2
FormatButton False, cmd1
Me.lbl1.Caption = "Off"
Me.lbl2.Caption = "On"
End If

End Sub

'------------------------------------

Function FormatButton(IsOn As Boolean, ctrl As control)

'sets the toggle button appearance on/off
If IsOn Then
ctrl.BorderColor = ColBlue
ctrl.BackColor = ColBlue
ctrl.ForeColor = vbWhite
ctrl.Alignment = 3
Else
ctrl.BorderColor = vbBlack
ctrl.BackColor = vbWhite
ctrl.ForeColor = vbBlack
ctrl.Alignment = 0
End If

End Function

'------------------------------------

Private Sub Form_Load()
'set cmd1 button 'on' and cmd2 'off'
Me.lbl1.Caption = "Off"
cmd1_Click

End 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