T
Tony_VBACoder
In Access 2002, does anyone know the best method for
removing selected items from a Multi-Select ListBox?
On my Form, I have one Multi-Select ListBox and one button
that allows the user to delete the selected item(s) from
the ListBox. I have tried to following 2 methods to
remove the selected items from the list box. However, in
my looping routine, when I issue the .RemoveItem command,
all the items that were selected in the Multi-Select list
box, become unselected, thereby leaving no items
selected. For instance, if the user has 5 items selected,
the first time the .RemoveItem code is issued, all the
items become deselected, leaving me with no items selected.
Private Sub btnRemoveTo_Click()
Dim vItem As Variant, iRow As Integer
' Remove all the items selected from the list box.
With Me
If .listSendTo.ItemsSelected.Count = 0 Then
Exit Sub
Else
' METHOD #1
For iRow = 0 To .listSendTo.ListCount - 1
If .listSendTo.Selected(iRow)
Then .listSendTo.RemoveItem iRow
Next
' METHOD #2
For Each vItem In .listSendTo.ItemsSelected
.listSendTo.RemoveItem vItem
Next
End If
End With
End Sub
removing selected items from a Multi-Select ListBox?
On my Form, I have one Multi-Select ListBox and one button
that allows the user to delete the selected item(s) from
the ListBox. I have tried to following 2 methods to
remove the selected items from the list box. However, in
my looping routine, when I issue the .RemoveItem command,
all the items that were selected in the Multi-Select list
box, become unselected, thereby leaving no items
selected. For instance, if the user has 5 items selected,
the first time the .RemoveItem code is issued, all the
items become deselected, leaving me with no items selected.
Private Sub btnRemoveTo_Click()
Dim vItem As Variant, iRow As Integer
' Remove all the items selected from the list box.
With Me
If .listSendTo.ItemsSelected.Count = 0 Then
Exit Sub
Else
' METHOD #1
For iRow = 0 To .listSendTo.ListCount - 1
If .listSendTo.Selected(iRow)
Then .listSendTo.RemoveItem iRow
Next
' METHOD #2
For Each vItem In .listSendTo.ItemsSelected
.listSendTo.RemoveItem vItem
Next
End If
End With
End Sub