Good afternoon all. I am working on a "dark mode" for a few of my users. I have a button to turn dark mode on, which works fine, but when I close and re-open the form, it reverts back to the normal "Day Mode" defaults. I have multiple forms I need to do this with. I have a Yes/No field in a reference table that the Dark Mode button sets to TRUE and then converts all text boxes on the form to black background and white bold font text.
Code:
Public Sub DarkMode()
Dim MyControl As Control
Dim MyTxt As TextBox
For Each MyControl In Screen.ActiveForm.Controls
If MyControl.Tag = 99 Then
Set MyTxt = MyControl
MyTxt.ForeColor = vbWhite
MyTxt.BackColor = vbBlack
MyTxt.FontWeight = 700
Set MyTxt = Nothing
End If
Next MyControl
End Sub
On the button, in the On Click, I call:
Code:
Me.DarkMode = True Call Module6.DarkMode
Me.Refresh
This does what it needs to do. But when I close and re-open the form with this code on the form's "On Load" event:
If Me.DarkMode.value = True Then
Call Module6.DarkMode
End If
I get "You entered an expression that requires a form to be the active window" at the following line in the Public Sub
For Each MyControl In Screen.ActiveForm.Controls
It looks like it is loading the module before the form loads, and I can't figure out how to force it to run the module when it loads to keep the form in dark mode... I also need to be able to turn comboboxes dark.