Page 2 of 2 FirstFirst 12
Results 16 to 22 of 22
  1. #16
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    #FFD700 in BackColor shows correct color. In a conversion calculator FFD700 returns decimal 16766720. That decimal does not return correct RGB(). Swap FF and 00 for D7FF in calculator and that returns 55295 which does return correct RGB() with latest code. All the decs I have in table now return correct RGB. Nice work Dave. Hopefully I can remember all this next time it comes up.



    Stumbling block is starting with color code #xxxxxx and trying to get Decimal then RGB. Simple helper function.
    Code:
    Function ColorHexToDec(Hex As String) As Long
    'convert 6 character Hex color code to decimal
    Dim r As String, g As String, b As String
    Hex = Replace(Hex, "#", "")
    r = Replace(Right(Hex, 2), "0", "")
    g = Mid(Hex, 3, 2)
    b = Left(Hex, 2)
    ColorHexToDec = CDbl("&H" & r & g & b)
    End Function
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  2. #17
    davegri's Avatar
    davegri is offline Excess Access
    Windows 11 Access 2019
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,413
    Hopefully I can remember all this next time it comes up.
    I keep code like this in my MZTOOLS code library.

  3. #18
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    I have the code, it's just remembering why had to build it the way it is.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #19
    davegri's Avatar
    davegri is offline Excess Access
    Windows 11 Access 2019
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,413
    Beating a dead horse, this code checks itself by converting the calculated decimal value back to hex and comparing it to the original function argument.

    Code:
    Function HexToDec(Hx As String) As Long
        'convert Hex color code to decimal
        Dim r As String, g As String, b As String, chk As String
        If Len(Hx) <> 6 And Len(Hx) <> 7 Then
            MsgBox "Input error to function HexToDec()" & vbCrLf & vbCrLf _
            & "The hex value must be 6 characters long." & vbCrLf _
            & "It optionally may have '#' on the left side making it 7 characters long.", _
            vbOKOnly + vbInformation, " C H E C K   F O R M A T "
            Exit Function
        End If
        Hx = UCase(Replace(Hx, "#", ""))
        r = Left(Hx, 2)
        g = Mid(Hx, 3, 2)
        b = Right(Hx, 2)
        chk = Hex(("&H" & r & g & b))   'convert result back to decimal and
        If chk <> Hx Then               'compare with original input parameter
            MsgBox "A conversion error has occured in function HexToDec()"
        Else
            HexToDec = ("&H" & r & g & b)
        End If
    End Function

  5. #20
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,980
    My Colour Converter app gives the same results as quoted by @Micron in post #14

    Click image for larger version. 

Name:	Capture.PNG 
Views:	16 
Size:	14.9 KB 
ID:	51687

    Seems I read somewhere that only the VB colors have &H values and my testing supports.
    Disagree. All colours can be described using HEX, RGB & OLE values.
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  6. #21
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Apparently had not tested all 8 &H codes in my table and turns out had some wrong. Fixed Green, Blue, Yellow, Magenta but Green and Yellow along with Gold still won't work.

    Okay, not understanding &H codes and will ignore.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #22
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,474
    This is another site I have used for colors https://www.endprod.com/colors/

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Change colour of Excel Row
    By DMT Dave in forum Access
    Replies: 1
    Last Post: 01-24-2019, 01:47 PM
  2. VBA for colour coding
    By SWG in forum Forms
    Replies: 1
    Last Post: 08-29-2012, 05:20 PM
  3. Changing the colour of a cell?
    By WayneSteenkamp in forum Access
    Replies: 3
    Last Post: 03-08-2012, 10:12 AM
  4. subform background colour
    By gbmarlysis in forum Forms
    Replies: 1
    Last Post: 03-03-2012, 10:18 AM
  5. Colour Searching and Referencing...
    By ABitOfANoob in forum Programming
    Replies: 8
    Last Post: 11-23-2011, 04:01 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