I have a form bound directly to a table and the form has a delete button. I was having issues with the regular menubar delete feature behaving unpredictably, so I coded it myself, but now, it's giving me an runtime error "Could not update; currently locked." If I go to another record, then return to the record I want to delete, however, it runs fine. What am I doing wrong?
Private Sub cmdDeleteRecord_Click()
Dim com As New ADODB.Command
Dim strSQL As String
If MsgBox("Are you sure you want to delete this?", vbYesNo, "Careful!") = vbYes Then
strSQL = "DELETE tblEmployeeMMTaskCat.*, tblEmployeeMMTaskCat.Employee_id, tblEmployeeMMTaskCat.Task_Category_id " & _
"FROM tblEmployeeMMTaskCat WHERE (((tblEmployeeMMTaskCat.Employee_id)= " & Me.Employee_id & ") " & _
"AND ((tblEmployeeMMTaskCat.Task_Category_id)=" & Me.Task_Category_id & "));"
With com
.CommandText = strSQL
.ActiveConnection = CurrentProject.Connection
End With
com.Execute
Me.Requery
DoCmd.GoToRecord , , acLast
End If
End Sub