Mike_Excel2003
New Member
- Joined
- Jul 20, 2011
- Messages
- 6
Hi.
I want a user to be able to click on any value in a combobox whle holding down the Shift key, and have the code remove that value (ultimately, with a cautionaty prompt to do so).
After, have all the remaining elements stay in the combobox and display the first element as the 'header' of that combobox.
The errors I am getting just seem random, unpredictible and illogical - almost human like!!. It's unreal, even to the point a msgbox is essential to force a refresh of an internal property.
I've been working on this for days, and have exhausted my ideas on how to get it working. Please, be so kind as to show me the way.
Thanks.
Mike.
I want a user to be able to click on any value in a combobox whle holding down the Shift key, and have the code remove that value (ultimately, with a cautionaty prompt to do so).
After, have all the remaining elements stay in the combobox and display the first element as the 'header' of that combobox.
The errors I am getting just seem random, unpredictible and illogical - almost human like!!. It's unreal, even to the point a msgbox is essential to force a refresh of an internal property.
I've been working on this for days, and have exhausted my ideas on how to get it working. Please, be so kind as to show me the way.
Thanks.
Mike.
Code:
Private Sub ComboBox2_MouseDown _
(ByVal Button As Integer, _
ByVal Shift As Integer, _
ByVal X As Single, _
ByVal Y As Single)
Dim entry_to_be_deleted As String
'
'
' Note: Runs whenever left mouse click selects ComboBox
' or mouse is used to click (and deselect) outside the ComboBox
'
' How to get shift+select
' wroking in a ComboBox came from Michael S. Meyers-Jouan and Johan deWispelaere
' http://visualbasic.ittoolbox.com/groups/technical-functional/vb-vba-l/distinguish-between-click-and-shiftclick-in-vba-excel-1820618
'
If Shift Then
MsgBox "" ' This seems essential to force ComboBox2.ListIndex _
' to refresh to take on the index of the selected _
' element in the Combo box
ComboBox2.RemoveItem ComboBox2.ListIndex ' this sometimes throws up an error (is it because ListIndex sometimes = -1???}
ComboBox2.Text = ComboBox2.List(0) ' I want to have an element show in the header of the ComboBox.
' although having it be the element one above the element just deleted is much
' is more preferred.
' sometimes get the combo box looking totally empty, other times not.
End If
End Sub