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 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