当我在主组合框中选择选项1时,我想禁用所有15个组合框,当选择选项2时,我要禁用10个组合框并启用5,当选择选择选项3时,我想要禁用5个组合框且启用10。我正在使用主组合框的后更新。我对这15个组合框使用取消销售/enable=True/False。我想知道是否有一种简单的方法可以做到这一点,而不是为每个组合框写单独的禁用/启用,这可能像一个循环?
假设您有15个名称类似cbo01、cbo02。。。等等并且您可以从选项组名称frameCombos(其中有3个选项(中设置enabled属性。
也许这是你想知道的简单方法。大概
Private Sub FrameCombos_AfterUpdate()
disableCombos Me.FrameCombos.Value
End Sub
Private Sub disableCombos(optVal As Byte)
Dim i As Byte, j As String
Const prefixCbo As String = "cbo"
Select Case optVal
Case 1
'disable all combos
For i = 1 To 15
If i < 10 Then
j = "0" & i
Else
j = i
End If
Me.Controls(prefixCbo & j).Enabled = False
Next i
Case 2
'disable 10 combos (cbo01, ..., cbo10)
'enable 5 combos (cbo11, ..., cbo15)
For i = 1 To 15
If i < 10 Then
j = "0" & i
Else
j = i
End If
If i <= 10 Then
Me.Controls(prefixCbo & j).Enabled = False
ElseIf i >= 11 And i <= 15 Then
Me.Controls(prefixCbo & j).Enabled = True
End If
Next i
Case 3
'enable 5 combos (cbo01, ..., cbo05)
'disable 10 combos (cbo06, ..., cbo15)
For i = 1 To 15
If i < 10 Then
j = "0" & i
Else
j = i
End If
If i <= 5 Then
Me.Controls(prefixCbo & j).Enabled = False
ElseIf i >= 6 And i <= 15 Then
Me.Controls(prefixCbo & j).Enabled = True
End If
Next i
End Select
End Sub