Hi,

I have a listbox(MultiSelect: 2 - Extended) in which I set ItemData index values for every item that goes into the box. I'll call this listbox myListBox.

The ItemData index values match their respective ID's from a mysql database.

What I need to be able to do is to:
Select multiple items at once and delete those selected items from the database

I found this code through Google.

<code>
Private Sub cmdMovetoRight_Click()
Dim i As Integer
If List1.ListIndex = -1 Then Exit Sub
For i = List1.ListCount - 1 To 0 Step -1
If List1.Selected(i) = True Then
List2.AddItem List1.List(i)
List1.RemoveItem i
End If
Next i
End Sub
</code>

What I need to be able to do is to use this code in some manner with myListbox above. I need to be able to return the ItemData index value of myListBox.Selected(i) using the code above.

Does anyone know how to do this?

Any help would be grately appreciated.

hi, i hope this would give you an idea.. :)
hope some expert can give you a clearer idea. :)

Private Sub cmdMovetoRight_Click()
Dim i, num As Integer
Dim strdata as String

num = 1 ' initialize counter

If List1.ListIndex = -1 Then Exit Sub
For i = List1.ListCount - 1 To 0 Step -1
If List1.Selected(i) = True Then

strdata = List1.Selected(i).Value 'not sure if this would be .value pls. check

'rs is the reference to your recordset in you database change if needed
    Do While Not rs.EOF
        ' See if the data has been found
        If  strdata= rs!DatabaseDataThen
            'do something here
        End If

        ' If not found move to the next record.
        num = num + 1
        rs.MoveNext
    Loop

List1.RemoveItem i
num = 1 'initialize loop again
End If

Next i
End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.