且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

删除记录,移动previous不工作

更新时间:2023-12-05 19:21:22

好像你在调试模式下的错误。不要设置的DoCmd命令的断点。这将总是失败。

如果不是这种情况,那么在这里你可以找到的实现要通过使用书签什么可能的方式之一: http://www.granite.ab.ca/access/positioning_on_a_continuous_form.htm

请注意的例子是连续的形式,但你可以得到的想法。

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.