This code works except that when there are multiple choices selected in listbox lstChosenOnes. The code will delete the first choice, but not any of the subsequent ones. When I watched the variables change, varItem remains on the user's original first choice when it should be iterating down to whatever the next choice the user has chosen in the list box.
Can anyone help me? Thank you. See code below:
Private Sub cmdDeleteChosenOnes_Click()
Dim frm As Form
Dim ctl As Control
Dim varItem As Variant
Dim dbCurrent As Database
Dim strSQL As String
Dim strDeleteQuery As String
Set frm = Forms!frmDeleteChosenOnes
Set ctl = frm!lstChosenOnes
Set dbCurrent = CurrentDb
For Each varItem In ctl.ItemsSelected
varItem = ctl.Column(0)
strDeleteQuery = "Delete * FROM tblChosenOnes
WHERE ChosenOnes = '" & varItem & "';"
DoCmd.RunSQL (strDeleteQuery)
Next varItem
End Sub
Can anyone help me? Thank you. See code below:
Private Sub cmdDeleteChosenOnes_Click()
Dim frm As Form
Dim ctl As Control
Dim varItem As Variant
Dim dbCurrent As Database
Dim strSQL As String
Dim strDeleteQuery As String
Set frm = Forms!frmDeleteChosenOnes
Set ctl = frm!lstChosenOnes
Set dbCurrent = CurrentDb
For Each varItem In ctl.ItemsSelected
varItem = ctl.Column(0)
strDeleteQuery = "Delete * FROM tblChosenOnes
WHERE ChosenOnes = '" & varItem & "';"
DoCmd.RunSQL (strDeleteQuery)
Next varItem
End Sub