Loopy Controls

hi there

Registered User.
Local time
Today, 13:55
Joined
Sep 5, 2002
Messages
171
Hi folks,

I've run into a little snag with one of my forms and i was hoping someone could help me with this. here's the problem. i have a form with various data validation controls that erases the invalid value and changes the BackColor property of the controls when invalid data is entered. I would like this formatting to be retained when the current record losses focus. I need to write a For...Next loop that loops thru each control and determines if the control is Null. If the control is Null then it changes the BackColor property to 65280. I can't seem to get this to work, could someone help me with the code. I think i need a nested If statement in a For...Next loop but i'm not sure how to set up the For....Next loop.

Thanks very much.
 
Code:
Private Sub Form_Current()
Dim ctrl As Control

    For Each ctrl In Me.Controls
        If ctrl.ControlType = acTextBox Then ctrl.BackColor = vbWhite
    Next

    If Me.NewRecord = False Then
    For Each ctrl In Me.Controls
        If ctrl.ControlType = acTextBox Then
                If IsNull(ctrl.Value) Then
                    ctrl.BackColor = 65280
                Else
                    ctrl.BackColor = vbWhite
                End If
        End If
    Next
    End If

End Sub

Give this a try. It will change only text boxes, but you can adapt it. A new record will have all of the text boxes reset back to white.

HTH
 
thanks for the response Pdx_man. i'll give it a try.
 

Users who are viewing this thread

Back
Top Bottom