Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing Colors in VBA

Status
Not open for further replies.

HenriM

Programmer
Sep 9, 2002
56
GB
I could use some code that would allow me to control the Font weight, Fore and Back Colors in forms and reports.

Logically one would expct this to be straightforward :-

'If Me.Mood = "Frustrated" then
Me.Face.Fore_Color = (color code for White)
Me.Face.Back_Color = (color code for Red)
Me.Face.Font_Weight = (Code for "Bold")
End If'

All of these elements are in the Properties dialog box as constants but is there any way of bringing them into code so that they can change with certain criteria?
The drop-down box in the code window allows nearly everything, .Visible etc but not these so of it is possible at all there should be another way.

Also The Back Color of raised and sunken objects defaults to grey and cannot be changed. Command Buttons are always raised and can't be set to Flat. So it seems that if you want a red button, you can have it as long as you make it grey!

Has anyone any ideas?

HenriM
 
hi

do not quite understand your question, you can do as you say, as long as you get the property name right:

Me.Face.ForeColor = (color code for White)
Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
The "simple" colors are enumerated as in vbWhite, vbRed, vbGreen

The shades can be generated as RGB(myred, mygreen, myblue)
where my* are byte (integer values of 0 to 255).

You can get some of the (hex) values by using the 'color picker' in controls "ForeColor" (or "BackColor") properties and use them directly if they meet you needs.

as in me.myctrl.backcolor = 16711680

will set the designated control's back color to the standard "Blue", while

me.myctrl.backcolor = 16777215 reesults in a "White" background
MichaelRed
m.red@att.net

Searching for employment in all the wrong places
 
Hallo,

As I understand it buttons are grey. But you can make your own coloured button using a red rectangle. Make it raised, then OnMouseDown make it Sunken, and OnMouseUp make it raised again.

I did something like this ages ago (in Access '97) but it worked ok. You may have to put the raising code in something like the LostFocus event as well in case the user clicks on the button but does not release until they have removed the mouse. I seem to remember there was something like that. May be it was OnClick, I dunno.

Have fun,

- Frink
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top