Clear Selections from a listbox

  • Thread starter Thread starter Byron
  • Start date Start date
B

Byron

How can I programatically clear all selections made in a
listbox that is designated as multi-select.
 
Try: me![lstMyListbox].itemsselected.count = 0

but I don't have Access here to check, so I may be wrong on that.

HTH,
TC
 
In the OnClick event of a button, put the following code changin
"YourListBox" to the name of your listbox...

Code
-------------------

Dim varItem As Variant

For Each varItem In Me.YourListBox.ItemsSelected
Me.YourListBox.Selected(varItem) = False
Next varItem
 
TC said:
Try: me![lstMyListbox].itemsselected.count = 0

but I don't have Access here to check, so I may be wrong on that.

I checked, the Count property is read only, so rhat won't
work.
 
Byron said:
How can I programatically clear all selections made in a
listbox that is designated as multi-select.


I seem to remember that this is a tricky issue and that

List0.RowSource = List0.RowSource

was a good way to do it.
 
Byron said:
How can I programatically clear all selections made in a
listbox that is designated as multi-select.

I've used this:

Dim intI As Integer

With Me.lstMyListBox

For intI = (.ItemsSelected.Count - 1) To 0 Step -1
.Selected(.ItemsSelected(intI)) = False
Next intI

End With

You must substitute your list box's name for "lstMyListBox".
 
For I = 0 To Me!lstDirList.ListCount - 1
Me!lstDirList.Selected(I) = SetSelected
Next

Set SetSelected to false to clear selections and true to select all selections
 
Back
Top