从记录中删除项目时出现错误3021出现错误、项目

2023-09-08 11:21:41 作者:七罪兽i

当我使用code以下,我有时会收到一个错误3021这只是发生时,我在记录一个记录。你能告诉我为什么,以及如何解决它?看来我已经竭尽所能!

感谢

 私人小组cmdDelSelectedAction_Click()

响应= MSGBOX(你确定吗?,vbYesNo,需要确认书)
如果响应= vbNo然后退出小组

如果我。[排列,操作子窗体] .Form.Recordset.EOF然后
    我。[排列,操作子窗体] .Form.Recordset.Move previous
结束如果

如果我。[排列,操作子窗体] .Form.Recordset.BOF然后
    我。[排列,操作子窗体] .Form.Recordset.MoveNext
结束如果

我。[排列,操作子窗体] .Form.Recordset.Delete
我。[排列,操作子窗体] .Form.Recordset.MoveNext

结束小组
 

解决方案

这已经有一段时间,但我认为,code是这样的:

 私人小组cmdDelSelectedAction_Click()
  昏暗REC作为记录=我。[排列,操作子窗体] .Form.Recordset
  如果没有rec.BOF或不rec.EOF然后
    如果MSGBOX(你确定吗?,vbYesNo,确认)= vbYes然后
      rec.Delete
    结束如果
  结束如果
结束小组
 
发布项目常见错误

我觉得有点怪,在你的code你会问,以确认要删除的记录,然后删除记录之前,您将执行MoveNext的或在记录一个移动previous。我会远离这样做,因为最终用户可能会被删除不同的记录比他们期待。

When I use the code below, I sometimes receive a Error 3021. This only happens when I have one record in the recordset. Can you please tell me why, and how to fix it? It seems I've tried everything!

Thanks

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

解决方案

It's been a while, but I think the code would look like this:

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

I find it a little odd that in your code you would ask to confirm to delete the record, and then before deleting the record, you would perform a MoveNext or a MovePrevious on the recordset. I would stay away from doing that since the end user might be deleting a different record than they were expecting.

 
精彩推荐
图片推荐