How to Set BackColor for a Label on a Form using VBA (1 Viewer)

flyinghippo99

Registered User.
Local time
Today, 13:47
Joined
Feb 28, 2011
Messages
53
Hey Guys,

So, I got a label created from using CreateControl. Let's call the label ctl.
I can set the Name, FontBold, Caption, etc. just fine.

However, I'm running to a problem setting the BackColor. I've did a search on MSDN and tried their examples as well as the examples on this forum and no color is set!

So, I tried this approach:

Dim lngRed as Long
lngRed = RGB(255,0,0)
ctl.BackColor = lngRed

I also tried

ctl.BackColor=RGB(255,0,0)

ctl.BackColor = vbRed.

None of that worked! And the color I want is not Red(but I only know the coding for red. hehe). The color I want is called "Background Dark Header" as it's called from the Property Sheet Format section for the label. But what is "Background Dark Header" equivalent to in numerical or RGB format? Is there even a lookup table for the various colors and their associated RGB codes? I couldn't find one.

Thanks!

flyinghippo
 

boblarson

Smeghead
Local time
Today, 13:47
Joined
Jan 12, 2001
Messages
32,059
Make sure that the BackStyle is not set to Transparent but is set to Normal or else the color won't show.
 

missinglinq

AWF VIP
Local time
Today, 16:47
Joined
Jun 20, 2003
Messages
6,423
Transparent is the Default for this property, so unless the OP has reset it that is most likely the problem.

Linq ;0)>
 

flyinghippo99

Registered User.
Local time
Today, 13:47
Joined
Feb 28, 2011
Messages
53
Transparent is the Default for this property, so unless the OP has reset it that is most likely the problem.

Linq ;0)>

Missinglinq & boblarson:

Thanks! I did not realize that BackColor default is Transparent. I set it to 1. So, now it's visible. However, I'm still looking for the numeric code for the color I'm interested it. Where can I find a color table lookup? Or how can I calculate those values myself?

thanks!

flyinghippo
 

boblarson

Smeghead
Local time
Today, 13:47
Joined
Jan 12, 2001
Messages
32,059
Where can I find a color table lookup? Or how can I calculate those values myself?
For which version of Access?

Access 2003 and earlier uses either a numeric value (which you can get by setting something to that color and then look at the value in the color property) or RGB where you provide Red, Green, and Blue values from 0 to 255 for each.

Access 2007 and above uses a Hex Value which one would THINK would convert by using any Hex Editor. But they don't. So, again, the easiest way is to select something, change the color to what you want and then make a note of the value that it puts in.
 

flyinghippo99

Registered User.
Local time
Today, 13:47
Joined
Feb 28, 2011
Messages
53
For which version of Access?

Access 2003 and earlier uses either a numeric value (which you can get by setting something to that color and then look at the value in the color property) or RGB where you provide Red, Green, and Blue values from 0 to 255 for each.

Access 2007 and above uses a Hex Value which one would THINK would convert by using any Hex Editor. But they don't. So, again, the easiest way is to select something, change the color to what you want and then make a note of the value that it puts in.

bob,

thanks! I figured it out which coincidentally is the same as your 2nd suggestion. In Access 2007, they don't have the number code anymore. At least I don't see it. "Background Dark Header" numeric code can be found by using the VBA editor and selecting the control(label in this case) and look at the property pane to see the number. Then I use that number to set it via VBA code.

you and this forum are great resources!

thanks everyone!

flyinghippo
 

Simon_MT

Registered User.
Local time
Today, 21:47
Joined
Feb 26, 2007
Messages
2,177
We careful with a Label Background = Transparent. If you cycle through records the Label font goes to Bold.

Simon
 

Users who are viewing this thread

Top Bottom