need to convert vb long or hex colour to display properly in access

Shawn
Shawn used Ask the Experts™
on
I have a table with a list of colours acutally from word. I have the Hex color and also the vb long equivalent.
When I put in the vb  long number for say the backcolour of a text field it gives me the wrong colour. After a little research I found out that access uses a converted rgb number.

So in vb long if I type in 255 is get blue but access gives me red.

Private Sub wPalette1_Click()

Me.wPalette1.BackColor = 255
Me.HighLightColour.BackColor = Me.wPalette1.BackColor

End Sub

any help is appreciated before I pull all of my hair out.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2016

Commented:
why not try using QBColor

QBColor Function
 


Returns a Long representing the RGB color code corresponding to the specified color number.

Syntax

QBColor(color)

The required color argument is a whole number in the range 015.

Settings

The color argument has these settings:

Number Color Number Color
0 Black 8 Gray
1 Blue 9 Light Blue
2 Green 10 Light Green
3 Cyan 11 Light Cyan
4 Red 12 Light Red
5 Magenta 13 Light Magenta
6 Yellow 14 Light Yellow
7 White 15 Bright White
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems Analyst
Top Expert 2007

Commented:

Author

Commented:
hi capricorn1:, won't work because those aren't the colours I want. below is a list of them.
ColorCodeID	CSSName	Hex	WordinternalName	VBLong	WordinternalColorCode
3	black	000000	wdBlack	0	1
4	blue	0000FF	wdBlue	255	2
8	lime	00FF00	wdBrightGreen	65280	4
10	navy	000080	wdDarkBlue	128	9
9	maroon	800000	wdDarkRed	8388608	13
11	olive	808000	wdDarkYellow	8421376	14
14	silver	C0C0C0	wdGray25	12632256	16
6	gray	808080	wdGray50	8421504	15
7	green	008000	wdGreen	32768	11
1			wdNoHighlight		0
5	fuschia	FF00FF	wdPink	16711935	5
13	red	FF0000	wdRed	16711680	6
15	teal	008080	wdTeal	32896	10
2	aqua	00FFFF	wdTurquoise	65535	3
12	purple	800080	wdViolet	8388736	12
16	white	FFFFFF	wdWhite	16777215	8
17	yellow	FFFF00	wdYellow	16776960	7

Open in new window

Should you be charging more for IT Services?

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Author

Commented:
DatabaseMX: no idea how this would help

with my simple example how would I do this?

Private Sub wPalette1_Click()
Me.wPalette1.BackColor = 255
Me.HighLightColour.BackColor = Me.wPalette1.BackColor
End Sub
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems Analyst
Top Expert 2007

Commented:
What about the RGB() function

RGB(red, green, blue)

?

Author

Commented:
RGB()  ok, but the question now is how would I get the rgb for my colours above?
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems Analyst
Top Expert 2007

Commented:
Using the function from the other Q link I posted.

mx

Author

Commented:
back to my previous questi
>with my simple example how would I do this?

pasted and saved code below in a module. but how on earth would I call it?

sorry I'm a little tired today and my head just isn't wrapping around this.
Private Declare Sub CopyMemory Lib "kernel32" _
   Alias "RtlMoveMemory" _
  (ByRef Destination As Any, _
   ByRef Source As Any, _
   ByVal Bytes As Long)
 
Private Declare Function OleTranslateColor Lib "olepro32.dll" _
  (ByVal OLE_COLOR As Long, _
   ByVal HPALETTE As Long, _
   pccolorref As Long) As Long
 
 
Private Function GetRBGFromOLEColour2(ByVal dwOleColour As Long) As Byte()
   
  'pass a hex colour, return the rgb components
   Dim clrref As Long
   Dim b(1 To 4) As Byte
   
  'translate OLE color to valid color if passed
   OleTranslateColor dwOleColour, 0, clrref
 
  'copy the color into a byte array
  'the size of the long (4 bytes)
   CopyMemory b(1), clrref, 4
   
  'return the byte array. Note there
  'is no value in byte(4).
   GetRBGFromOLEColour2 = b()
 
End Function
 
 
'Now func uses long
'but this is how we can also use Hex or long
e.g.
 
 
Public Sub testit()
   Dim dwOleColor As Long
   Dim clrs() As Byte
   
   'Pass in hex or long
   dwOleColor = &H80000018
   clrs() = GetRBGFromOLEColour2(16777215)
   
   Debug.Print "R", clrs(1)
   Debug.Print "G", clrs(2)
   Debug.Print "B", clrs(3)
 
   Debug.Print RGB(255, 255, 255)
 
End Sub

Open in new window

Commented:
the combined color is Red(0-255)+Green(0-255)^2+Blue(0-255)^3
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems Analyst
Top Expert 2007

Commented:
gRay ... are you sure?

The Access color for White is 16777215

Red(255)+Green(255)^2+Blue(255)^3 = 16711425

?
255^1              255
255^2 =       65025
255^3 = 16581375

mx

Commented:
Let me correct that:

R*256 + G*256^2 + B*256^3

Where R,G,B can have the values 0-255

Sorry about that.
Commented:
Still got it wrong:

color = R * 256^0 + G*256^1 + B * 256^2

Commented:
of course 256^0 = 1

Commented:
? 255.0 + 255.0*256 + 255.0*256^2
 16777215
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems Analyst
Top Expert 2007

Commented:
ummm ... 255*256^3  by itself    = 4278190080

what am I missing

Commented:
What am I missing - it's been a while since I studied that stuff.  Finally got it right as you can see from my previous.
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems Analyst
Top Expert 2007

Commented:
Where the hell did M$ ever come up with this bizarre formula ??

Apparently in A2007, you can now specify RGB !

thx for that formula btw ...

mx

Commented:
Actually VB but I guess that is M$ ;-)

Author

Commented:
ok got it, thanks guys

Commented:
Thanks, glad to help

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial