区分更新和MS Access Form.AfterUpdate中的插入 [英] Differentiate between updates and inserts in MS Access Form.AfterUpdate

查看:81
本文介绍了区分更新和MS Access Form.AfterUpdate中的插入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在MS Access中有一个绑定表格.我想能够告诉:

I have a bound form in MS Access. I want to be able to tell:

  1. 插入新记录时
  2. 更新现有记录时

我认为事件Form.AfterUpdateForm.AfterInsert对此非常合适,但是我刚刚测试了Form.AfterUpdate,发现它在更新并插入后触发.

I thought the events Form.AfterUpdate and Form.AfterInsert would be perfect for this, but I just tested Form.AfterUpdate and found that it fires after updates and inserts.

是否可以通过Form_AfterUpdate()判断更新和插入之间的区别?还是我应该考虑使用另一种方法来检测Access中的这些事件?

Is there some way to tell the difference between updates and inserts from within Form_AfterUpdate()? Or is there another approach to detecting these events within Access that I should consider?

Private Sub Form_AfterInsert()
    Debug.Print "after insert"
End Sub

Private Sub Form_AfterUpdate()
    Debug.Print "after update"
End Sub

当我插入新记录时,将打印此记录:

When I insert a new record, this is printed:

after update
after insert

当我更新现有记录时,将打印此记录:

When I update an existing record, this is printed:

after update

推荐答案

如果您真的只需要知道这是一个新记录承诺还是现有记录承诺,请使用BeforeUpdate事件设置一个模块级变量,然后可以在AfterUpdate事件中被读取.

If you really just need to know if this was a new or existing record commitment, use the BeforeUpdate event to set a module-level variable that can then be read in the AfterUpdate event.

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

这篇关于区分更新和MS Access Form.AfterUpdate中的插入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆