troubleshooting Question

Code to delete item selected in list box from table

Avatar of Megin
Megin asked on
Microsoft Access
8 Comments1 Solution429 ViewsLast Modified:
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
     
Next i
ctl.Requery



CurrentDb.Execute strsql, dbFailOnError



End Sub

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!
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 8 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros