Set object color scheme via code

A

AccessNubee

Access 2003.
Is there a way to set the background colors of objects by code behind a
form?
For example, have all the lables ( lbl* ) set to one color or transparent,
the data fields set to another ( str* ), boxes to another ( box* ) etc...
I am designing the user interface and setting these colors for each field
manually is a real pain in the butt since we have tons of fields per form
and tons of forms....and we still haven't decided on a specific color scheme
yet. :( Each workgroup will have their own version of the front end with a
different color scheme....
 
D

Daniel Pineault

The basic synthax is Me.FormControlName.BackColor = ColorNumber

Example
Me.txtPassword.BackColor = 2220398

You could easily cover the previous into a more generic function which loops
through all the control on a form and reset the background color based on the
type of control using a case statement.

The following might help you get started
**************
Dim ctl As Control

For Each ctl In Me.Form.Controls
Select Case ctl.ControlType
Case acTextBox
ctl.BackColor = 2220398

Case acLabel
ctl.BackColor = 638934

Case acListBox
ctl.BackColor = 3346278

'...
'Check vba help on ControlType for a complete listing

Case Else

End Select
Next ctl
**************
It loops through all the controls on a form and changes the backcolor per
the preset values.
--
Hope this helps,

Daniel Pineault
http://www.cardaconsultants.com/
For Access Tips and Examples: http://www.devhut.com/index.php
Please rate this post using the vote buttons if it was helpful.
 
A

AccessNubee

This is exactly what I have been looking for !!! :)
I put it in the "OnLoad" event and it changes everything to the colors I
specify. Now all I have to do is change the colors in the code once. This is
soo much faster than editing all the controls individually during
development....
I do understand that once we get the colors the way we want it, it should be
entered in the properties of the controls. :)

Oh and by the way, in case anyone out there doesn't know this, if you open
Windows Calculator and change it to scientific, you can click the HEX
option, enter any hex color code, then select the Dec (decimal) button and
you get the color number for Access. :)
 
J

Jan Baird

Jan Baird is out of the country until September 20. Every effort will be
made to respond to messages, but please be patient.
 
J

Jan Baird

Jan Baird is out of the country until September 20. Every effort will be
made to respond to messages, but please be patient.
 
J

Jan Baird

Jan Baird is out of the country until September 20. Every effort will be
made to respond to messages, but please be patient.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top