Remove from list box ?

G

GGill

In my form i have 2 list boxes and command button 'cmdAdd'. when I select
from list box 'lstAvailable' and click on button then it will add to second
list box 'lstSelected'., so my code for button add on click works fine. I am
trying to find out how can i remove when i double click on second list box
'lstSelected' (the row source type for that list box is Value List, control
source nothing).
Please help me !!!!
Thank you.
=======
Private Sub cmdAdd_Click()

Dim InvListCounter As Integer, InvCurrentCounter As Integer
Dim InvListItems As Integer, InvCurrentItems As Integer
Dim ListStr As String, FoundInList As Integer


InvListItems = [lstAvailable].ListCount - 1
InvCurrentItems = [lstSelected].ListCount - 1
For InvListCounter = 0 To InvListItems
If [lstAvailable].Selected(InvListCounter) = True Then
If IsNull([lstSelected].RowSource) Then
ListStr = [lstAvailable].Column(0, InvListCounter) & ";"
[lstSelected].RowSource = ListStr
Else
FoundInList = False
For InvCurrentCounter = 0 To InvCurrentItems
If [lstSelected].Column(0, InvCurrentCounter) = _
[lstAvailable].Column(0, InvListCounter) Then
FoundInList = True
End If
Next InvCurrentCounter
If Not FoundInList Then
ListStr = [lstSelected].RowSource & _
[lstAvailable].Column(0, InvListCounter) & ";"
[lstSelected].RowSource = ""
[lstSelected].RowSource = ListStr
End If
End If
End If


Next InvListCounter

End Sub
==========
 
M

Michel Walsh

Hi,


If you use a value list, you have to remove the substring from the string.

str = Replace( "," & myList , ", " & substring , vbNullString)


will replace the substring with nothing. You must also check to see if the
first char is a "," and have to remove it if so:


if( Left(str, 1) = "," ) then str = Mid(str, 2)


and now, supply that string as the new list.



Hoping it may help,
Vanderghast, Access MVP
 

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

Similar Threads

Multi List Box Add/Delete 0
List Box Add/Delete [RE-POST] 0
List Box 1
Multiselect List Box-Access 2002 8
Select from List Box 5
VBA Coding Help for Beginner 0
For Without Next Error 1
Creating collection woes 2

Top