Unselect a selection in a combo box

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 17:41
Joined
Feb 28, 2001
Messages
30,201
I have a multi-column combo box, but it is not a multi-select case. Therefore, there is no flag that tells me a given row was selected. (I've looked at the properties - 'tain't there.) I have a case where I want to un-select the current contents of the combo box without closing the form to do it. It is read-only because the form is unbound. The combo box uses a ROWSOURCE but not a CONTROLSOURCE.

.UNDO doesn't seem to help, nor does .REQUERY

The situation is that user Joe Schmuckatelli has committed a previous change to one of the items for which he is responsible. At that point, I want to deselect the selection that brought him to the item he changed. It is a cascading combo box case, though through VBA rather than using a direct form reference to another control. I have to do that because I have to take into account that Joe doesn't touch the same items as Tommy Thumbfingers, so the ROWSOURCE needs more in it for the second combobox than just that one field from the first combo box.
 
Would this work:

Code:
Dim v As Variant

'Deselect the individual items
For Each v In Me.MyComboBox.ItemsSelected
    v.Selected = False
Next

'Clear the selection (to remove the "empty box" that could 
'do funny things)
Me.MyComboBox = Null

I'm not sure if the last line is actually applicable as I seem to recall that it always returns null for multi-select listbox but I remember having problems where the listbox would have first item "selected" (but not highlighted as if a user actually selected it) or something like that and that was needed to clear that away, I think.
 
Found something else online that did it.

There is a control property for list box and combo box when not using multi-select (which I'm not, in this case), where you set the property x.ListIndex to -1 (but for some reason you have to do it twice). You ALSO have to store a blank in the .SelText property and that requires that the control must be in focus first.

Doing that forces the combobox or list box to no longer have a selection left over from a prior use.
 

Users who are viewing this thread

Back
Top Bottom