vba 使用表单事件检测数据更改

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4402005/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 12:24:27  来源:igfitidea点击:

Detecting data changes with Form events

ms-accessvbams-access-2007access-vba

提问by RolandTumble

If you've read my other recent questions, you've prob'ly picked up that I'm not reallyan Access developer.... Most of my background is in VB, where I assiduously avoided bound controls.

如果您阅读了我最近的其他问题,您可能已经发现我并不是真正的 Access 开发人员....我的大部分背景都在 VB 中,在那里我刻意避免绑定控件。

Now I'm working in Access 2007. I have form that's based on a table (well, a single-table query), and a subform upon it based on a one-to-many child table. I want to detect user-made changes in the data on either of these forms so that I can update a date stamp in the parent table. The actual date field is not being shown to the user (at least not here).

现在我在 Access 2007 中工作。我有一个基于表的表单(好吧,一个单表查询),以及一个基于一对多子表的子表单。我想检测用户对这些表单中的数据所做的更改,以便我可以更新父表中的日期戳。实际的日期字段没有显示给用户(至少在这里没有)。

What would be the appropriate event to catch the fact that the change has been made? How should I make the actual change (direct to form.Recordset!dateField | with a hidden bound text box | some other way)?

什么是适当的事件来捕捉已进行更改的事实?我应该如何进行实际更改(直接到 form.Recordset!dateField | 带有隐藏的绑定文本框 | 其他方式)?

回答by Philippe Grondier

You'll have to look for the afterupdate event, which is fired when the updated content of a bound control is updated in the underlying recordset.

您必须查找 afterupdate 事件,当绑定控件的更新内容在基础记录集中更新时会触发该事件。

In this event procedure, you should be able to write the needed instruction to update your date field. It is not necessary to have it bound to any control on the form, as long as the field is in the recordset!

在此事件过程中,您应该能够编写更新日期字段所需的指令。只要该字段在记录集中,就没有必要将其绑定到表单上的任何控件!

回答by mannypacman

I think you can make a trigger to update the stamp of the child table per line of item that the user have made changes. I normally use it on afterupdate event in relation to the index number of the active line (if you are in a datasheet form or continues form) being edited. But of course you can count on how many times each record was updated and you can update the stamp date of the last update.

我认为您可以创建一个触发器来更新用户所做更改的每行项目的子表的戳记。我通常在与正在编辑的活动行(如果您是数据表表单或继续表单)的索引号相关的 afterupdate 事件上使用它。但是当然您可以计算每条记录的更新次数,并且您可以更新上次更新的戳日期。