C
cherman
Hi there. I want to remove the selected items from a listbox. I'm using the
following code I got the from another post, but it doesn't work correctly.
Dim varItem As Variant, lngSelected() As Long, lngLoop As Long
If Me.lstAll_Filter_Values.ItemsSelected.Count > 0 Then
ReDim lngSelected(Me.lstAll_Filter_Values.ItemsSelected.Count - 1)
lngLoop = 0
For Each varItem In Me.lstAll_Filter_Values.ItemsSelected
lngSelected(lngLoop) = varItem
lngLoop = lngLoop + 1
Next varItem
For lngLoop = UBound(lngSelected) To 0 Step -1
Me.lstAll_Filter_Values.RemoveItem Index:=lngLoop
Next lngLoop
End If
If, for example, I have 5 items and the 1st 3 are selected then it works
like a charm, but if I have the last 2 selected or 1, 3 & 5 then it doesn't
work right. It seems to remove the right # of items, but not the right items.
Can someone help me modify this to work properly or give me another solution?
Thanks!
following code I got the from another post, but it doesn't work correctly.
Dim varItem As Variant, lngSelected() As Long, lngLoop As Long
If Me.lstAll_Filter_Values.ItemsSelected.Count > 0 Then
ReDim lngSelected(Me.lstAll_Filter_Values.ItemsSelected.Count - 1)
lngLoop = 0
For Each varItem In Me.lstAll_Filter_Values.ItemsSelected
lngSelected(lngLoop) = varItem
lngLoop = lngLoop + 1
Next varItem
For lngLoop = UBound(lngSelected) To 0 Step -1
Me.lstAll_Filter_Values.RemoveItem Index:=lngLoop
Next lngLoop
End If
If, for example, I have 5 items and the 1st 3 are selected then it works
like a charm, but if I have the last 2 selected or 1, 3 & 5 then it doesn't
work right. It seems to remove the right # of items, but not the right items.
Can someone help me modify this to work properly or give me another solution?
Thanks!