I have some code that should take a selected item from a list box and delete it from a table. Here is the code:
Private Sub btnDeleteStaff_Click()
Dim frm As Form
Dim ctl As Control
Dim db As DAO.Database
Dim strsql As String
Dim i As Variant
Set frm = Forms("frm_Staff")
Set ctl = frm![lstExistingStaff]
Set db = CurrentDb
For Each i In ctl.ItemsSelected
strsql = "DELETE FROM Staff WHERE " & _
"[Staffid] = " & ctl.Column(2, i) & " AND [Lname] = '" & ctl.Column(3, i) & "' AND [fName] = '" & ctl.Column(4, i) & "' And [StartDate] = " & ctl.Column(5, i) & " And [EndDate] = " & ctl.Column(6, i) & "AND [Compid] = " & ctl.Column(7, i) & ""
db.Execute strsql, dbFailOnError
CurrentDb.Execute strsql, dbFailOnError
When I try to run it, it does nothing. I don't even get an error code.
I know there is a way to check to see if the code is running at all, but I can't remember how to do that. Also, this is basically the same code I use in another form and it worked fine there. Of course, I changed out the form name, table name, and control names, but everything else is the same.
Thank you, in advance!