区分更新和MS Access Form.AfterUpdate中的插入 [英] Differentiate between updates and inserts in MS Access Form.AfterUpdate
问题描述
我在MS Access中有一个绑定表格.我想能够告诉:
I have a bound form in MS Access. I want to be able to tell:
- 插入新记录时
- 更新现有记录时
我认为事件Form.AfterUpdate
和Form.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屋!