Changing colour of foreground in an obj

Hudson

New member
Local time
Yesterday, 19:59
Joined
May 2, 2011
Messages
9
Hi

Easy one for you here....how do you change the foreground colour of a form object say when you click on it. I have tried this:

Private Sub lblTony_Click()
lblTony.ForeColor = #ED1C24
End Sub

and other similarities but can't get the syntax right. The access helpline mentions the function RGB but this is not recognised by my version of access.

cheers
 
If you need version-specific help it would probably be a good idea to give the version you're running!

2007/2007 use Hex numbers for colors, I believe. Here's a site with an extensive list of them as well as a generator

http://www.2createawebsite.com/build/hex-colors.html

2003 and earlier uses RGB as well a as a Windows coloring scheme. What I've always done, because it doesn't require consulting a list or memorizing is to
  1. In Design View, select an object
  2. Goto Properties-Format
  3. Set it color to the object using the pallet
  4. Copying whatever color code then shows up
  5. Use this in my code
Linq ;0)>

Late Note: While many sites give Hex color values with the # sign preceding them, I believe when actually using them in code the pound sign or octothorp is omitted!
 
Last edited:
thanks for the reply. However in code the following :

lblTony.ForeColor = £#BA1419 or
lblTony.ForeColor = #£BA1419 or
lblTony.ForeColor = £BA1419

do not work. Please can you help as its really annoying.

Cheers
 
Its alright got it now...you can just write it as vbGreen or vbRed. Good enough for me for now.

Cheers

Hudson
 
Even better is you can use Conditional Formatting for this. There is an option for FIELD HAS FOCUS and you can set the formatting there and then there is no code necessary.
 
I've used that approach, too! Actually, the whole thing of clicking on a Label to change it's color is sort of an odd requirement! You'd have to reset the color in moving to another record, or in Datasheet/Coninuous View, use your Textbox-as-a-Label appropach. I've used OnMouseMove property of a Textbox or Command Button to change it's colors or to pop up appropriate help (hate ControlTip Text!) but never found a reason to do a Lable in this manner.

Linq ;0)>
 

Users who are viewing this thread

Back
Top Bottom