Free Lessons Courses Seminars TechHelp Fast Tips Templates Topic Index Forum ABCD

 Home   Courses   Index   Templates   Seminars   TechHelp   Forums   Help   Contact   Join   Order   Logon More... What's New? Popular Links ------------ Access Courses Access Index Access TechHelp Access Forum Access Troubleshooter ------------ Excel Courses Excel Index ------------ Code Vault Testimonials Tip Jar

 Home > Forums > Access
 Back to Access Forum    Comments List
 Maurice Loucel         2 months ago
I found a few ways to convert HEX to DEC using VBA.
But I am sure you have a better way, now just in case this is the code I found:

`Public Function GetHexColor(strHex As String) As Long[COLOR="Green"]    '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)[/COLOR]        Dim strColor As String    Dim strR As String    Dim strG As String    Dim strB As String    [COLOR="Green"]    'strip the leading # if it exists[/COLOR]    If Left(strHex, 1) = "#" Then        strHex = Right(strHex, Len(strHex) - 1)    End If    [COLOR="Green"]    'reverse the first two and last two hex numbers of the R G B values[/COLOR]    strR = Left(strHex, 2)    strG = Mid(strHex, 3, 2)    strB = Right(strHex, 2)    strColor = strB & strG & strR    GetHexColor = CLng("&H" & strColor)End Function`
 2 months ago If it works, it works. :)

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Forum.