Remove selected items from multiselect listbox

Yusuf

Active Member
Joined
Jun 1, 2004
Messages
337
Hi

Is there a quick way of doing this.
I have quite a few listboxes that operate on one screen. The user can select items from any of the listboxes and a Refresh command button will trigger the items to be removed.

If it's possible, are you able to advise me on a method or code for only one listbox.
I would simply mirror this code for the other listboxes

Many thanks
Y
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Here is the code to reset a list box, just change the lstSelected name to the listbox name

Private Sub cmdReset_Click()

lstSelected.RowSource = ""

End Sub
 
Last edited:
Upvote 0
Hi Trevor

Does this work with only the selected items or will it clear the listbox completely?

Regards
Y
 
Upvote 0
Yes Y,

The code would remove all items from the list box, to remove just the once you select use this code (change the lstSelected name to your control name):

Private Sub Command18_Click()
Dim i As Integer
For i = lstSelected.ListCount - 1 To 0 Step -1
If lstSelected.Selected(i) Then lstSelected.RemoveItem i
Next i
End Sub
 
Upvote 0
Hi

I get an Compile error: Method or Data member not found

RemoveItem is highlighted. Could this be that I'm using Access 97?


Regards
Y
 
Upvote 0
Yusuf

How exactly are you populating the listbox(s)?

In Access there is no RemoveItem or AddItem for listboxes.
 
Upvote 0
Yusuf

How exactly are you populating the listbox(s)?

In Access there is no RemoveItem or AddItem for listboxes.

Norie sorry but there is a removeItem, certainly in access 2007.

As my previous code works in 2007 and again I explored this as follows

Dim i As Integer
For i = lstSelected.ListCount - 1 To 0 Step -1
If lstSelected.Selected(i) Then lstSelected.RemoveItem i
Next i
 
Upvote 0
Trevor

But there isn't in early versions.:)

The error message the OP describes indicates they are using an earlier version than 2007.

I can't quite see the use of either method in Access, normally when working with a listbox it would be bound to a record source.
 
Upvote 0
Hi

Good question guys. I must admit that this didn't even cross my mind.

The listbox is populated by a table and upon thinking about it, the data should be removed from that table.

I would like to delete the selected items


Thanks
Y
 
Upvote 0

Forum statistics

Threads
1,213,486
Messages
6,113,932
Members
448,533
Latest member
thietbibeboiwasaco

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top