Results 1 to 6 of 6
  1. #1
    NikoTheBowHunter is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2017
    Posts
    58

    Change Text box background color when checkbox is checked

    On my form there is a text box that all our notes get entered into called [Notes History]. I would like to add a new checkbox to my form for defective items. So that when the box is checked the background color for [Notes History] changes from the default gray to red. When its unchecked the background goes back to the default gray.



    How would this be done? I would imagine something with the "on client event" for the check box but as I have little knowledge of this I turn to you good peeps

    checkbox name would be [DEFECTIVE]
    Text box for notes is named [Notes History]

  2. #2
    NikoTheBowHunter is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2017
    Posts
    58
    Well I thought I had it figured out...

    Code:
    If Me.DEFECTIVE = True Then
    [Notes History].BackColor = 255
    Else
    [Notes History].BackColor = BFBFBF
    End If
    End Sub
    When the checkbox is clicked it does change to red as desired but when its unchecked the text box goes black and not back to the default gray. Any ideas?

  3. #3
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,511
    If Me.DEFECTIVE = True Then
    [Notes History].BackColor = 255
    Else
    [Notes History].BackColor = 12566463
    End If

    http://www.endprod.com/colors/

  4. #4
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,741
    Setting color properties with VBA is a complex enterprise. IF you want to use the # notation, you have to convert it first to a decimal number. Here's a function to do that:
    Code:
    Public Function fcnHexColToRGB(ByVal hexColor As String) As String
        On Error GoTo fcnHexColToRGB_Error
        'Example HexColor = "#00FF1F"
        Dim Red As String
        Dim Green As String
        Dim Blue As String
        hexColor = Replace(hexColor, "#", "")
        Red = Val("&H" & Mid(hexColor, 1, 2))
        Green = Val("&H" & Mid(hexColor, 3, 2))
        Blue = Val("&H" & Mid(hexColor, 5, 2))
        fcnHexColToRGB = RGB(Red, Green, Blue)
            'The output is an RGB value
        On Error GoTo 0
        Exit Function
    fcnHexColToRGB_Error:
        MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure fcnHexColToRGB"
    End Function
    If you plug in your value "#BFBFBF", you will get 12566463.

    So the working code would be
    Code:
    Else
    [Notes History].BackColor = 12566463

  5. #5
    Micron is offline Very Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    simple if using constants
    BackColor = vbred
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  6. #6
    NikoTheBowHunter is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2017
    Posts
    58
    Thank you for the replies!!! converting/using the decimal version worked like a charm!! Knew this was the right place to come to. Thank you again everyone for your help!!! cheers!

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

Similar Threads

  1. Change Text color and/or background color
    By Thompyt in forum Reports
    Replies: 2
    Last Post: 02-23-2017, 07:08 PM
  2. Replies: 4
    Last Post: 08-29-2015, 07:38 AM
  3. Replies: 4
    Last Post: 10-28-2014, 09:51 AM
  4. Replies: 2
    Last Post: 06-01-2014, 12:05 PM
  5. Change Row Background Color Programmatically
    By sales@4bco.com in forum Programming
    Replies: 2
    Last Post: 10-25-2009, 11:17 AM

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