通过单击工具栏的删除按钮来删除多条记录。
之前做个一个使用了记录集例子,比较麻烦。可删除数据表窗体多条记录并提示所选记录的信息。
这里分享一个更加简单的方法。数据表或连续窗体均可:
方法一:
Option Compare Database Option Explicit Dim stDel As String Dim inDel As Integer Private Sub Form_BeforeDelConfirm(Cancel As Integer, Response As Integer) Response = acDataErrContinue End Sub Private Sub Form_Delete(Cancel As Integer) If Me.SelHeight > inDel Then stDel = stDel & Chr(13) & " " & Me.编号 inDel = inDel + 1 Cancel = True End If If Me.SelHeight = inDel Then If MsgBox("您正准备删除 " & inDel & " 条编号如下的记录:" & Chr(13) & stDel & Chr(13) & _ Chr(13) & "删除后将不能撤消,确定删除吗?", vbExclamation + vbYesNo, "确认删除") = vbYes Then inDel = Me.SelHeight + 1 DoCmd.RunCommand acCmdDeleteRecord End If inDel = 0 stDel = "" End If End Sub
方法二:
Option Compare Database Option Explicit Dim stDel As String Dim inDel As Integer Private Sub Form_BeforeDelConfirm(Cancel As Integer, Response As Integer) Response = acDataErrContinue If MsgBox("您正准备删除 " & inDel & " 条编号如下的记录:" & Chr(13) & stDel & Chr(13) & _ Chr(13) & "删除后将不能撤消,确定删除吗?", vbExclamation + vbYesNo, "确认删除") = vbNo Then Cancel = True End If End Sub Private Sub Form_Delete(Cancel As Integer) stDel = stDel & Chr(13) & " " & Me.编号 inDel = inDel + 1 End Sub