我正在尝试创建一个Access GUI,让用户可以在提交之前自由编辑数据。
但是,如果不循环到运行时错误3167“记录被删除”,它将不允许我自由删除数据。显然它与我告诉它从通过表格显示的实时表中删除数据这一事实有关。
有人能告诉我一种可以解决这个问题的方法吗?
Private Sub Cmd_delete_batch_Click()
Dim RS As Recordset
Dim ls_Batch_type As String
Dim ls_batch_no As String
If MsgBox("This action will delete all selected Mail Merge Items. Are you Sure?", vbYesNo, "Mail Merge Delete Warning") = vbNo Then
Exit Sub
End If
Set RS = FRM_Batch.Form.RecordsetClone
RS.MoveFirst
For i = 1 To RS.RecordCount
If RS.Fields("SELECT_FLAG") = True Then
CurrentDb.Execute "DELETE * FROM tblFinalMailMerge WHERE SELECT_FLAG = True"
End If
RS.MoveNext
Next i
FRM_Batch.Form.Requery
答案 0 :(得分:2)
在我看来,您要删除用户已将tblFinalMailMerge
设置为True的SELECT_FLAG
中的所有记录。所以我认为没有必要为此使用记录集。只需执行DELETE
语句。
If MsgBox("This action will delete all selected Mail Merge Items. " & _
"Are you Sure?", vbYesNo, _
"Mail Merge Delete Warning") = vbYes Then
CurrentDb.Execute "DELETE FROM tblFinalMailMerge " & _
"WHERE SELECT_FLAG = True", dbFailOnError
End If