I'm trying to delete a record and then move to the one before the deleted record. But I can't get it to work, and now I'm getting
run-time error 2046 The command or action 'DeleteReord' isn't available now.
What am I doing wrong here? How should I handle this?
Private Sub Command24_Click()
On Error GoTo Err_Command24_Click
If Me![dbo_HR_Trainings Subform].Form.Recordset.RecordCount > 0 Then
MsgBox "You cannot delete a category that has members.", vbOKOnly
GoTo Exit_Command24_Click
Else
Select Case MsgBox("Are you sure you want to delete this category?", vbYesNo, "Are you sure?")
Case vbYes
DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdDeleteRecord
DoCmd.GoToRecord , , acPrevious
Case Else
End Select
End If
Exit_Command24_Click:
Exit Sub
Err_Command24_Click:
MsgBox Err.Description
Resume Exit_Command24_Click
End Sub
Seems like you get the error in Debug mode. Do not set a breakpoint on DoCmd commands. This will always fail.
If this is not the case, then here you can find one of the possible ways to accomplish what you want by using Bookmark: http://www.granite.ab.ca/access/positioning_on_a_continuous_form.htm
Please note the example is for continuous forms but you can get the idea.