Listbox and Arrays (x, y)

T

Terry

I have a combobox that I select items from and add to a listbox whos
recordsource is a valuelist.

If the listbox is multiselect and I need to remove selected rows, what would
be the best way? Do I need to read the whole valuelist list into an array
and manipulate it there before loading it back into the listbox? If I did
have to do that, how would I retain the array elements intact?

I would expect no more than about 12 rows / 2 columns in the listbox.

regards
 
S

Steve M.

Starting with Access 2002 if you are using a ValueList you can use
Me.RemoveItem(Index)
where Index is the row index of the item to remove

assuming you have a button that the user clicks after making selection(s) of items to remove ...

Private Sub cmdRemove_Click()

' the items selected property returns an array of the indexes
' of the selected items but they are stored as variants.

Dim varItem As Variant

For Each varItem In Me.MyList.ItemsSelected
Me.MyList.RemoveItem varItem
Next varID


End Sub
 
D

Dan Artuso

Hi,
If you don't have 2002, you can try this:

Dim varItem As Variant
Dim tempSource As String

tempSource = Me.List6.RowSource
For Each varItem In Me.List6.ItemsSelected
tempSource = Left(tempSource, InStr(1, tempSource, Me.List6.Column(0, varItem), vbTextCompare) - 1) & _
Mid(tempSource, InStr(1, tempSource, Me.List6.Column(0, varItem), vbTextCompare) _
+ Len(Me.List6.Column(0, varItem)) + 1)
Next
Me.List6.RowSource = tempSource

Just replace List6 with your listbox
Watch out for line wrap!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top