controls on a form ?

gbanks

Registered User.
Local time
Today, 21:49
Joined
Feb 9, 2000
Messages
161
This is part of a code on a form I use to change the color of the field base on whether the record is new or not. I want to change other fields on the form the same way. Do I have to list each field like I did the [To] field or is the a way to tell the form if this is a new record make all controls or text boxes on the form a certain color? Just looking for a shortcut. Thanks..
If Me.NewRecord Then
[To].BackColor = 16777215
Else
[To].BackColor = 9868950
 
Dim ctl as Control

If Me.NewRecord Then
For Each ctl in Me.Controls
ctl.BackColor = 16777215
Next
Else
For Each ctl in Me.Controls
ctl.BackColor = 9868950
Next
End If
 
just an modification on Scott's code to change textboxes only.

Code:
Dim ctl as Control 
 
If Me.NewRecord Then 
For Each ctl in Me.Controls 
If ctl.ControlType = acTextBox then 'Others include acLabel, acListBox, acComboBox, acCheckBox etc
ctl.BackColor = 16777215 
End if
Next 

Else 

For Each ctl in Me.Controls 
If ctl.ControlType = acTextBox then
ctl.BackColor = 9868950 
end if    
Next 

End If
 

Users who are viewing this thread

Back
Top Bottom