Delete multiple selected records in Listbox

hardrock

Registered User.
Local time
Today, 06:07
Joined
Apr 5, 2007
Messages
166
Dear all,

I have a list box on my form which loads data from a table. The table has a unique autonumber field, let’s call it “refno”,
I am trying to get a multiple select and delete to work. I am playing with the code below, assigned to a button. It doesn’t work and I can’t figure out why? Please help.

Private Sub DeleteItem_Click()
Dim strSelection As String, varItem As Variant
Dim strSQL As String
For Each varItem In Me.List1.ItemsSelected
'If the values are strings, use the following
strSelection = strSelection & """" & Me.List1.refno(varItem) & ""","
Next
'Remove the last ","
strSelection = Left(strSelection, Len(strSelection) - 1)
strSQL = "DELETE * FROM Orderbook WHERE Orderbook.refno IN (" & strSelection & ");"
CurrentDb.Execute strSQL, dbFailOnError
End Sub
 
I sorted it.

Dim varItem As Variant
Dim strItem As String
Dim ctl as object


Set ctl = Me!List1

For Each varItem In ctl.ItemsSelected
strItem = ctl.Column(1, varItem)

(delete routine)

Next varItem
 

Users who are viewing this thread

Back
Top Bottom