VIDEO: Modern On Off Buttons in Access
I recorded a YouTube video that demonstrates how to implement the Modern On/Off button feature that I wrote about yesterday.
I recorded a companion video to go with yesterday's article about creating modern On/Off buttons in Microsoft Access.
Support for Continuous Forms
One of the problems with the solution I wrote about yesterday is that it did not work so well for continuous forms.
Here's a screenshot of the original approach to see what I mean:
To address this issue, I added an optional parameter to the FormatToggle()
function to hide the disc icon. When the disc icon is hidden, the border also remains blue for both the ON and OFF positions.
Here's the updated look:
It's not as nice as the one with the circle that slides from left to right, but it's still easier to read at a glance than a checkbox. I'm not sure how often I would use this feature in a continuous form, but at least now it's an option.
The (Improved) Code
This fix required no changes to the CreateModernOnOff()
routine that I wrote about yesterday. Refer to that article to get the code for CreateModernOnOff()
.
The following code is a complete (backwards-compatible) replacement for the FormatToggle()
function from yesterday's article:
'Companion function to CreateModernOnOff() procedure (https://nolongerset.com/modern-on-off/)
'Source : https://nolongerset.com/modern-on-off-video/
'This is version 2 of the FormatToggle() function
' - added Optional ShowCaption parameter to better support continuous forms
Function FormatToggle(ToggleBtn As ToggleButton, _
Optional ShowCaption As Boolean = True)
Const Buffer As Long = 2
With ToggleBtn
If ShowCaption Then
If .Value Then
'When button is ON, leading spaces force
' disc icon to the right
.Caption = Space(Buffer) & "l"
.BorderColor = vbBlue
Else
'When button is OFF, trailing spaces force
' disc icon to the left
.Caption = "l" & Space(Buffer)
.BorderColor = vbBlack
End If
Else
.Caption = ""
.BorderColor = vbBlue
End If
End With
End Function