我在编写进程以在输入新数据时更改每个控件的背景颜色。当控件为空时,我的代码没有问题。但是当我开始输入值或从组合框中选择值时,它不起作用。此外,该过程对DateTimePicker不起作用。 任何大师能帮助我吗?非常感谢你!
Public Sub Control_Change()
Dim ctrl As Control
Dim ans As Long
For Each ctrl In Me.Controls
If ctrl.Name <> "cboProjectHealth" Then
Select Case True
Case TypeOf ctrl Is MSForms.CheckBox, TypeOf ctrl Is MSForms.OptionButton
Select Case ctrl.Value
Case True
ctrl.BackColor = vbWhite
Case Else
ctrl.BackColor = vbBlue: ans = ans + 1
End Select
Case TypeOf ctrl Is MSForms.TextBox, TypeOf ctrl Is MSForms.ComboBox
Select Case ctrl.Value
Case vbNullString
ctrl.BackColor = vbBlue: ans = ans + 1
Case Else
ctrl.BackColor = vbWhite
End Select
Case TypeOf ctrl Is DTPicker
Select Case ctrl.Value
Case vbNullString
ctrl.CalendarBackColor = vbBlue: ans = ans + 1
Case Else
ctrl.CalendarBackColor = vbWhite
End Select
End Select
End If
Next ctrl
End Sub