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
| Option Compare Database
Option Explicit
Private Sub MyTextBox_BeforeUpdate(Cancel As Integer)
**Call ChangeColorCaption(MyTextBox, RGB(25, 160, 240))
End Sub
Private Sub ChangeColorCaption(TxtBox As TextBox, ByVal ChangedColor As Long)
Dim oCtl As Control
Dim oLabel As Label
Dim oForm As Form
Dim strContent As Variant
Dim strLabel As String
Dim lngColor
**strContent = TxtBox.Text
**If IsNull(strContent) Or Len(strContent) = 0 Then
****lngColor = RGB(0, 0, 0)
**Else
****lngColor = ChangedColor
**End If
**Set oForm = Form
**Set oCtl = TxtBox
**strLabel = oCtl.Controls.Item(0).ControlName
**Set oLabel = oForm.Controls(strLabel)
**oLabel.ForeColor = lngColor
**Set oCtl = Nothing
**Set oForm = Nothing
**Set oLabel = Nothing
End Sub |
Partager