I have a combobox control in a form made for an Excel application, using VBA. Let's suppose that the combobox is called cmb010. Next to it there are 2 other controls called txt011, cmb012 and txt013. These controls are inside the third page of a multipage control (which is the only such control in the whole form).
The control was generated dynamically in the Initialize event of the form, and was assigned the values "YES" and "NO" during its initialization. The other controls that I mention to you were generated in the same way.
What I want to do is, that if the value "NO" is selected in control cmb010, the controls txt011 and cmb012 must be disabled and the control txt013 must receive the focus.
I generated this code to perform the above actions:
Private Sub cmb010_Change()
Dim response As String
response = cmb010.Value
With Me.MultiPage1.Pages(2) ' Page 3, index 2
If response = "NO" Then
.Controls("txt011"). Enabled = False
.Controls("cmb012").Enabled = False
.Controls("txt013").SetFocus
Else
.Controls("txt011").Enabled = True
.Controls("cmb012").Enabled = True
End If
End With
End Sub
Running this code does not give the response I expect. I click on the combobox called cmb010, select the item NO, but the controls are not disabled.
I have also tried other alternatives to find a solution, without success.
- Change the Change() event to Click() event.
- When initializing the ComboBox activate the Style property with the value fmStyleDropDownList.
I want to know what causes this behavior and how can I solve this problem. Thanks for your attention.