如何在打开表或更新字段时触发事件? [英] How to trigger an event when a table is opened or a field updated?

查看:116
本文介绍了如何在打开表或更新字段时触发事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

[Access 2003]


我在一年前创建了一个数据库,用于存储有关请求的信息用户用来更新报告。使用Microsoft Outlook表单更新数据库中的字段。基本上,用户打开Outlook表单,填写信息,将其发送到电子邮件组,数据输入数据库,电子邮件组的成员接收电子邮件。


通常情况下,Outlook表单工作正常,但很少有电子邮件会挂在用户的发件箱中。奇怪的是,Outlook表单背后的代码仍然处理并将数据输入数据库,但是电子邮件被发送到电子邮件组的成员,这有点违背了数据库的目的,因为它用于通知成员请求已提交的小组。


在未来的某个时刻,我计划对整个过程进行大修,并使用更稳定的东西,但暂时我会我已经决定通过制作我希望进行的一些小改动来实现应有的目标。


我要做的就是设置每当打开表格或在该表格中打开某些字段时,将向电子邮件组发送电子邮件的模块或宏(只有一个表...它是一个简单的数据库)。


我的问题是我不知道如何触发一个事件来监视表的打开或更改该表上特定字段中的数据。我实际上甚至不确定这是否可行,因为数据库可能只在发送电子邮件表单和处理数据之间的很短时间内打开。


这个数据库实际上根本没有打开,主要是只有在发送电子邮件表单时才有动作,所以我认为(我可能是错的)会消除使用计时器定期检查。


这是可能的,是否有一些示例代码我可以查看来创建我的模块/宏?


谢谢,

beacon

解决方案

嗨Beacon。根本没有与Access表关联的事件,因此我无法想到通过哪种方式可以实时检测到新的行插入或字段更新。


另一种可能值得考虑的方法是生成一个更改日志,显示已发生的所有插入或修改活动(日志中每次更改的时间戳以及用户ID等)。您可以设置Outlook代码,以便每次进行插入或字段更新时在更改日志中生成一个条目。


通过代码间隔监控更改日志表,您可以跟踪活动并根据需要发送新条目和更改的通知。


这只是一个想法,而不是目前完全形成的东西。更改日志记录实现相当简单(尽管您需要将相关数据库中保存的表的数量从一到两倍!)。


-Stewart

我担心在打开表或查询对象的过程中没有触发任何事件。只有Form和Report对象具有该功能(相关事件的集合)。


具体取决于您的Outlook代码中发生的具体情况(您不会在那里详细介绍)可能有点创意,但从根本上说,没有什么比你要求的我更害怕。字段永远不会打开,因此该部分也是禁止的。


@Stewart - 我已经设置的表基本上就像更改日志一样。问题是我不经常检查它,我希望避免检查它...如果数据发生变化,请选择通过电子邮件发送给我,让它对我有用。懒?也许吧,但如果每月只有一次或两次更新,我不想每天检查一些东西。你知道吗?


@NeoPa

Outlook表单背后的代码基本上使用DAO将表单上的值输入到相关字段中。


这是一个片段:

展开 | 选择 | Wrap | 行号


Hi everybody,

[Access 2003]

I created a database about a year ago that stores information about requests that users make to update reports. The fields in the database are updated using a Microsoft Outlook form. Basically, the user opens the Outlook form, fills in the info, sends it to an email group, the data is entered in the database, and the email is received by the members of the email group.

Usually, the Outlook form works just fine, but there have been few occasions when the email will get hung up in the user''s Outbox. Strangely enough, the code behind the Outlook form still processes and enters the data into the database, but the email is sent to the members of the email group, which somewhat defeats the purpose of the database since it''s used to notify the members of the group that a request has been submitted.

At some point in the future I plan on overhauling this whole process and using something a little more stable, but for the time being I''ve decided to make due with what I''ve got by making what I''m hoping are a couple of minor changes.

What I''m trying to do is setup a module or macro that will send an email to the email group whenever the table is opened or when certain fields are opened in that table (there''s only one table...it''s a simple database).

My problem is that I don''t know how to trigger an event that monitors the opening of a table or the changing of data in a specific field on that table. I''m actually not even sure this is possible since the database is likely only open for a very short amount of time between when the email form is sent and the data is processed.

This database really isn''t kept open at all and primarily only has action when an email form is sent, so I think (I could be wrong) that would eliminate using a timer to check periodically.

Is this possible and is there some example code I can view to create my module/macro?

Thanks,
beacon

解决方案

Hi Beacon. There are no events associated with Access tables at all, so there is no automatic way I can think of by which you could detect a new row insertion or a field update in real time.

An alternative approach which might be worth considering is to generate a change log showing all insertion or modification activity that has taken place (with a timestamp for each change in the log along with the user ID and so on). You could set up your Outlook code to make an entry in the change log each time an insertion or field update takes place.

By monitoring the change log table at intervals through code you could track activity and send out notifications of new entries and changes as necessary.

This is just an idea rather than something fully-formed at present. Change logging is fairly straightforward to implement (although you''d need to double the number of tables you hold in the DB concerned from one to two!).

-Stewart


I''m afraid there are no events triggered in the course of opening table or query objects. Only Form and Report objects have that facility (sets of associated events).

Depending on exactly what happens within your Outlook code (You don''t go into much detail there) it may be possible to be a little creative, but fundamentally there is nothing like what you ask for I''m afraid. Fields are never opened as such either, so that part is a no-go too.


@Stewart - The table I have already is setup basically like a change log. The problem is that I don''t check it that often and I was hoping to avoid having to check it...opting instead to make it work for me by emailing me if the data changed. Lazy? Perhaps, but I don''t like the idea of checking something daily if there may only be an update once or twice a month. Y''know?

@NeoPa
The code behind the Outlook form basically inputs the values on the form into the associated field using DAO.

Here''s a snippet:

Expand|Select|Wrap|Line Numbers


这篇关于如何在打开表或更新字段时触发事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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