通过单击工具栏的删除按钮来删除多条记录。 之前做个一个使用了记录集例子,比较麻烦。可删除数据表窗体多条记录并提示所选记录的信息。
这里分享一个更加简单的方法。数据表或连续窗体均可:
视图:
详细源码:
方法一:
Option Compare DatabaseOption ExplicitDim stDel As StringDim inDel As IntegerPrivate Sub Form_BeforeDelConfirm( _
Cancel As Integer, Response As Integer) Response = acDataErrContinueEnd SubPrivate 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 DatabaseOption ExplicitDim stDel As StringDim inDel As IntegerPrivate 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 IfEnd SubPrivate Sub Form_Delete(Cancel As Integer) stDel = stDel & Chr(13) & ' ' & Me.编号 inDel = inDel 1End Sub
联系客服