Magic_Doctor
Board Regular
- Joined
- Mar 18, 2009
- Messages
- 56
Hello,
On the sheet there is a ComboBox. Next to this a TextBox.
I choose an item in the ComboBox and I would like, as soon as the item is chosen, to select the TextBox to enter data. How to do it ?
I tried well, in the ComboBox procedure: TextBox.SetFocus, TextBox.Select, TextBox.Activate ... nothing works, crash every time.
Otherwise the macro works fine.
On the sheet there is a ComboBox. Next to this a TextBox.
I choose an item in the ComboBox and I would like, as soon as the item is chosen, to select the TextBox to enter data. How to do it ?
I tried well, in the ComboBox procedure: TextBox.SetFocus, TextBox.Select, TextBox.Activate ... nothing works, crash every time.
Otherwise the macro works fine.
VBA Code:
Sub ChangeItem(ComboName$)
'When you change the item in the ComboBox list, the percentage is canceled in the TextBox and the CheckBox is unchecked if it was
'Magic_Doctor
Dim suf As Byte, obj As Object, i As Byte, ad#
suf = ExtractNumber(ComboName) 'ComboBox suffix
Set obj = ActiveSheet.OLEObjects("TextBoxPP" & suf).Object 'TextBox "TextBoxPP"
obj.Value = Format(0, "##,##0.00""%""") 'displays 0 + formatting (-> 0.00%)
obj.Activate 'DO NOT WORK!!!
Set obj = ActiveSheet.OLEObjects("CheckBoxPP" & suf).Object 'CheckBox "CheckBoxPP"
If obj Then 'the CheckBox corresponding to the ComboBox is checked
obj = 0 'the CheckBox is unchecked
CheckSolvants = CheckSolvants - 1 'and hop! 1 less solvent checked
pourcents(suf) = 0 'the percentage will necessarily be 0 in the dynamic array "percent ()"
If CheckSolvants > 0 Then
For i = 1 To NbSolvants + 1 '(Base 0)
Set obj = ActiveSheet.OLEObjects("CheckBoxPP" & i).Object 'CheckBox "CheckBoxPP"
If obj Then ad = ad + pourcents(i) 'identification of CheckBoxes still checked and addition of their percentages
Next
Set obj = ActiveSheet.OLEObjects("TextBox_AddPourcent").Object 'TextBox "TextBox_AddPourcent"
obj.Value = Format(ad, "##,##0.00""%""") 'the TextBox "TextBox_AddPourcent" displays the sum of all percentages always checked + formatting (suffix "%")
End If
End If
End Sub