return to original colors?

  • Thread starter Thread starter N Lee
  • Start date Start date
N

N Lee

Is there a simple VBA command that will return all fields to their
original properties? I have a form where some fields change color, but
on a button press, I'd like them to return to the original color as
defined in the properties of Design view. I know I can just write a bunch of
field1.backcolor = vbwhite
field2.backcolor = vbwhite
....

but I'd rather not, because I have hundreds of fields on my forms. Any
ideas?

-Nathan
 
Will all the controls go to the white color? Then you could use some code to
loop through all the controls to set their property:

Dim ctl As Control
On Error Resume Next
For Each ctl in Me.Controls
ctl.BackColor = vbWhite
Err.Clear
Next ctl

Using On Error Resume Next means that the code will ignore errors raised if
a control does not have a backcolor property.
 
Hi,
There is no simple command.
You have a few choices.

You can loop through all the controls on a form and process them
that way or you can name specific controls in a manner which
will simulate a control array.

For example:
txtB1, txtB2, txtB3 etc

For i = ! To 3
Me("txtB" & i).backcolor = vbWhite
Next i

or you can use the Tag property to indicate a control should be processed.
 
Back
Top