1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| Private Sub Form_Load()
Dim ctl As Control
For Each ctl In Me.Controls
    If ctl.ControlType = acTextBox Then
        ctl.BeforeUpdate = "=TrackControl(""" & ctl.Name & """)"
    End If
Next ctl
Set ctl = Nothing
End Sub
Private Function TrackControl(ByVal ctlName As String)
Dim ctl As Control
For Each ctl In Me.Controls
    ' on utilise la propriété Parent pour trouver l'étiquette liée
    '  au contrôle en question
    ' on peut aussi utiliser
    '  Me.Controls(ctlName).Controls.Item(0).ControlName
    If ctl.ControlType = acLabel And ctl.Parent.Name = ctlName Then
        If IsNull(Me.Controls(ctlName)) = True Then
            ctl.ForeColor = RGB(0, 0, 0)
        Else
            ctl.ForeColor = RGB(25, 160, 240)
        End If
    End If
Next ctl
Set ctl = Nothing
End Function |
Partager