Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2014
    Posts
    11

    Unanswered: Changing Windows default blue background in datasheet cells without the focus

    Hi

    I'm a newbie beginner type and I've looked through a fair number of sheets of posts to see if this is in there but there's over a 1000 so I'll just have to ask...

    Is there a way to change the background colour of the cells in a datasheet that don't have focus. Windows defaults to a pale blue which is clashing with the rest of the form i'm creating, the colours of which are imposed by the user.

    I have attached a visual for clarity

    Thank you
    Attached Files Attached Files

  2. #2
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    Add this to a Standard Module:

    Code:
    Public Function HexColor(strHex As String) As Long
    
        'converts Hex string to long number, for colors
        'the leading # is optional
    
        'example usage
        'Me.iSupplier.BackColor = HexColor("FCA951")
        'Me.iSupplier.BackColor = HexColor("#FCA951")
    
        'the reason for this function is to programmatically use the
        'Hex colors generated by the color picker.
        'The trick is, you need to reverse the first and last hex of the
        'R G B combination and convert to Long
        'so that if the color picker gives you this color #FCA951
        'to set this in code, we need to return CLng(&H51A9FC)
        
        Dim strColor As String
        Dim strR As String
        Dim strG As String
        Dim strB As String
        
        'strip the leading # if it exists
        If Left(strHex, 1) = "#" Then
            strHex = Right(strHex, Len(strHex) - 1)
        End If
        
        'reverse the first two and last two hex numbers of the R G B values
        strR = Left(strHex, 2)
        strG = Mid(strHex, 3, 2)
        strB = Right(strHex, 2)
        strColor = strB & strG & strR
        HexColor = CLng("&H" & strColor)
    
    End Function

    Save the Module and name it HexColorConvert

    In Form Design View, select a Control and go to Properties - Format and select the BackColor, using the Color Palette. Note the Hex number that Access generates for this color. One shade of pink is #EFD3D2.

    Now use this code, loading the identified Hex number into the HexColor() function:
    Code:
    Private Sub Form_Load()
     
      Me.DatasheetBackColor = HexColor("#EFD3D2")
     
    End Sub

    You can set the BackColor when a Control/Cell has Focus using Conditional Formatting with the 'Field has Focus' Condition.

    I've had this code archived for several years, and sadly, do not have the name of the author.

    Linq ;0)>
    Last edited by Missinglinq; 09-09-14 at 23:12.
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  3. #3
    Join Date
    Sep 2014
    Posts
    11
    Thanks Missinglinq

    I did what you said but as you can see from attached screenshot the Fields without focus in first record are still blue

    All other cells do have Pink as their backcolor but i was quite happy with them white - perhaps it isn't the backcolor but something else that is blue?

    Any ideas?
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •