Q - I have list box called lstChosenOnes on a form called frmDeleteChosenOnes. Examples of choices in the List Box are like, Sally, Bob, Fred, and Joe. A User can pick one or more items selected in this list box. Upon selection, the user ought to be able to click a command button that deletes records from a table called tblChosen. In other words, if the user selects Bob and Fred, and then clicks the Command button, then the code should open the tblChosen, find Bob and Fred and Delete them. I've been trying something like this, but it's probably wrong - feel free to totally disregard it:
Set frm = Forms!frmDeleteChosenOnes
Set ctl = frm!lstChosenOnes
Set dbCurrent = CurrentDb
strSQL = "SELECT ChosenOnes FROM tblChosenOnes;"
Set rsChosenOnes = dbCurrent.OpenRecordset(strSQL)
strCriteria = "[ChosenOnes] = varItm
MsgBox "are you sure you want to delete these?", vbOKCancel
For Each varItm In ctl.ItemsSelected
'rsChosenOnes.FindFirst "ChosenOnes" = strCriteria
rsChosenOnes.FindFirst strCriteria
Debug.Print ctl.ItemData(varItm)
rsChosenOnes.Delete
It sounds like it should be relatively simple, but I am having a heck of a time with it. Can anyone help, or does anyone have some example code of something similar? I don't know if I have explained this adequately enough.
Thanks in advance:
S. Croce
SCroce13@aol.com
Set frm = Forms!frmDeleteChosenOnes
Set ctl = frm!lstChosenOnes
Set dbCurrent = CurrentDb
strSQL = "SELECT ChosenOnes FROM tblChosenOnes;"
Set rsChosenOnes = dbCurrent.OpenRecordset(strSQL)
strCriteria = "[ChosenOnes] = varItm
MsgBox "are you sure you want to delete these?", vbOKCancel
For Each varItm In ctl.ItemsSelected
'rsChosenOnes.FindFirst "ChosenOnes" = strCriteria
rsChosenOnes.FindFirst strCriteria
Debug.Print ctl.ItemData(varItm)
rsChosenOnes.Delete
It sounds like it should be relatively simple, but I am having a heck of a time with it. Can anyone help, or does anyone have some example code of something similar? I don't know if I have explained this adequately enough.
Thanks in advance:
S. Croce
SCroce13@aol.com