Results 1 to 5 of 5
  1. #1
    Bill the Cat is offline Novice
    Windows 10 Access 2016
    Join Date
    Dec 2019
    Location
    Virginia
    Posts
    24

    Create a "Dark Mode" for text boxes and comboboxes

    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.

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,293
    Pass in the form object to your sub.
    Not sure you need to keep setting mycontrol to Nothing in the loop.
    Perhaps just after the loop?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    Bill the Cat is offline Novice
    Windows 10 Access 2016
    Join Date
    Dec 2019
    Location
    Virginia
    Posts
    24
    That worked for the main form. I have to test it on a sub-form too, but that'll happen later. It does give me a type mismatch on

    Set MyTxt = MyControl


    on a form with a single combo box. Any idea why?

  4. #4
    davegri's Avatar
    davegri is online now Excess Access
    Windows 11 Access 2019
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,706
    Set MyTxt = MyControls ​??

  5. #5
    Bill the Cat is offline Novice
    Windows 10 Access 2016
    Join Date
    Dec 2019
    Location
    Virginia
    Posts
    24
    Quote Originally Posted by davegri View Post
    Set MyTxt = MyControls ​??
    oops... my mistake.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 4
    Last Post: 11-02-2023, 05:46 AM
  2. Replies: 23
    Last Post: 11-17-2022, 06:58 PM
  3. Replies: 4
    Last Post: 12-20-2015, 12:16 PM
  4. Export "Query or Report" to a "Delimited Text File"
    By hawzmolly in forum Import/Export Data
    Replies: 3
    Last Post: 08-31-2012, 08:00 AM
  5. Replies: 5
    Last Post: 09-02-2011, 03:44 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums