<Ap******@gmail.com> wrote in message
news:11**********************@u72g2000cwu.googlegr oups.com...
Hi
I have a form with 20 fields. When I place my form in EDIT mode, I
want all the
fields to have their BackColor set to Yellow. Can this be done without
having
to assign the color to each field individually with multiple
statements?
Thanks Greg
Yes you can, but your code should be able to set them back again as well.
So you could structure it like the sub below so that you will be able to
call either
SetEditMode True
or
SetEditMode True
but you only write one sub:
Private Sub SetEditMode(EditModeOn As Boolean)
On Error GoTo Err_Handler
Dim ctl As Control
Dim lngColor As Long
If EditModeOn Then
lngColor = vbYellow
Else
lngColor = vbWhite
End If
For Each ctl In Me.Controls
If TypeOf ctl Is TextBox Then
ctl.Properties("BackColor").Value = lngColor
End If
Next ctl
Exit_Handler:
Exit Sub
Err_Handler:
MsgBox Err.Description, vbExclamation, "Error No: " & Err.Number
Resume Exit_Handler
End Sub