ms-access - 区分 MS Access Form.AfterUpdate 中的更新和插入
问题描述
我在 MS Access 中有一个绑定表单。我希望能够告诉:
- 插入新记录时
- 更新现有记录时
我认为这些事件非常适合这个,但我刚刚测试Form.AfterUpdate
并发现它在更新和插入后触发。Form.AfterInsert
Form.AfterUpdate
有什么方法可以从内部分辨更新和插入之间的区别Form_AfterUpdate()
吗?或者我应该考虑在 Access 中检测这些事件的另一种方法吗?
Private Sub Form_AfterInsert()
Debug.Print "after insert"
End Sub
Private Sub Form_AfterUpdate()
Debug.Print "after update"
End Sub
当我插入一条新记录时,会打印:
after update
after insert
当我更新现有记录时,将打印:
after update
解决方案
如果您真的只需要知道这是新的还是现有的记录承诺,请使用BeforeUpdate
事件设置一个模块级变量,然后可以在AfterUpdate
事件中读取该变量。
Option Compare Database
Option Explicit
Dim booNew As Boolean
Private Sub Form_BeforeUpdate(Cancel As Integer)
booNew = Me.NewRecord
End Sub
Private Sub Form_AfterUpdate()
Debug.Print IIf(booNew, "New", "Existing")
End Sub
推荐阅读
- java - Spark java 代码在 spark_core v2.2 中运行,但在 spark_core v2.3 中失败
- regex - RUTA 脚本在没有空格的情况下无法识别模式
- excel - 运行时错误“438”对象不支持此属性或方法
- scala - 如何使用 Option 更改函数以在这两种情况下工作
- angular - dataItems 数组如何像 JSON 一样在视图中显示
- c# - 如果页面空闲几分钟,IdentityServer 4 ASP .NET Core MVC Ajax 调用将重定向到授权端点
- python - 使用 Python 将所有工件用户编译成列表
- winapi - pywinauto在virtualbox下的混合后端应用程序中找不到Win32元素
- wordpress - 如何在 Woocommerce 订单编辑页面上添加管理员通知
- python-3.x - 图表标题的可选参数,以允许覆盖当前生成的标题