Reputation: 9
When I select option 1 in the main combo box I want to disable all 15 combo boxes, when option 2 is selected I want to disable 10 combo boxes and enable 5 and when option 3 is selected I want to disable 5 combo boxes and enable 10. I am using afterupdate for the main combo box. I am using disbale/enable =True/False for the 15 combo boxes. I was wondering if there is an easy way to do this instead writing individual disable/enable for each combo box may like a loop?
Upvotes: 0
Views: 390
Reputation: 44
Say you have 15 combos with name like cbo01, cbo02, ...and so on. and you set the enabled property from option group name frameCombos (has 3 options in it).
Maybe this is the easy way you're wondering for. Maybe.
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
Upvotes: 0