1

当我使用下面的代码时,有时会收到错误 3021。仅当我在记录集中有一条记录时才会发生这种情况。你能告诉我为什么,以及如何解决它吗?看来我什么都试过了!

谢谢

Private Sub cmdDelSelectedAction_Click()

response = MsgBox("Are you sure?", vbYesNo, "Confirmation required")
If response = vbNo Then Exit Sub

If Me.[Arrangement-Actions subform].Form.Recordset.EOF Then
    Me.[Arrangement-Actions subform].Form.Recordset.MovePrevious
End If

If Me.[Arrangement-Actions subform].Form.Recordset.BOF Then
    Me.[Arrangement-Actions subform].Form.Recordset.MoveNext
End If

Me.[Arrangement-Actions subform].Form.Recordset.Delete
Me.[Arrangement-Actions subform].Form.Recordset.MoveNext

End Sub
4

1 回答 1

0

已经有一段时间了,但我认为代码看起来像这样:

Private Sub cmdDelSelectedAction_Click()
  Dim rec As Recordset = Me.[Arrangement-Actions subform].Form.Recordset
  If Not rec.BOF Or Not rec.EOF Then
    If MsgBox("Are you sure?", vbYesNo, "Confirm") = vbYes Then
      rec.Delete
    End If
  End If
End Sub

我觉得有点奇怪,在您的代码中您会要求确认删除记录,然后在删除记录之前,您将对记录集执行 MoveNext 或 MovePrevious。我不会这样做,因为最终用户可能会删除与他们预期不同的记录。

于 2013-08-06T19:48:29.310 回答