I have a form that I have create that has a list box set so that I can select drawing numbers from. I want to be able to delete those records from a table. I have the following code that I have placed in an event procedure On Click but it gives me this message when I try and run the code, "Update or CancelUpdate without AddNew or Edit."
This is my code.
Dim strSQL As String
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim ctl As Control
Dim varItem As Variant
On Error GoTo ErrorHandler
Set db = CurrentDb()
Set rs = db.OpenRecordset("testpackDetails_tbl", dbOpenDynaset)
'make sure a selection has been made
If Me.List9.ItemsSelected.Count = 0 Then
MsgBox "Must select at least 1 Drawing"
Exit Sub
End If
'delete selected value(s) from table
Set ctl = Me.List9
For Each varItem In ctl.ItemsSelected
rs.delete
rs!testdetails_id = ctl.ItemData(varItem)
rs.delete
Next varItem
ExitHandler:
Set rs = Nothing
Set db = Nothing
Exit Sub
This is my code.
Dim strSQL As String
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim ctl As Control
Dim varItem As Variant
On Error GoTo ErrorHandler
Set db = CurrentDb()
Set rs = db.OpenRecordset("testpackDetails_tbl", dbOpenDynaset)
'make sure a selection has been made
If Me.List9.ItemsSelected.Count = 0 Then
MsgBox "Must select at least 1 Drawing"
Exit Sub
End If
'delete selected value(s) from table
Set ctl = Me.List9
For Each varItem In ctl.ItemsSelected
rs.delete
rs!testdetails_id = ctl.ItemData(varItem)
rs.delete
Next varItem
ExitHandler:
Set rs = Nothing
Set db = Nothing
Exit Sub