如何在创建新记录时执行操作? [英] How to perform an action when a new record is created?

查看:104
本文介绍了如何在创建新记录时执行操作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一种感觉,我应该知道这一点,但我无法想到任何事情。我正在尝试为我的数据库(跟踪贷款)创建一个文件管理部分,以便可以随时访问与特定贷款相关的每个文档。我的计划是使用PK作为文件夹名称为每条记录创建一个文件夹,以便使用Windows资源管理器可以相对轻松地找到它。我想在创建记录时创建文件夹。但是,我无法想象要知道什么时候才能知道创建记录的时间。我不想在表格的'AfterUpdate事件中检查文件夹的存在,因为它会频繁触发,而且每次都不需要这样做。我正在寻找一个NewRecordModified属性。我想我可以使用表单的'OnCurrent事件来设置一个标志,当前记录是一个新记录。然后在'AfterUpdate事件的形式中,我可以测试该标志是否设置为NewRecord,然后创建该文件夹。但是,这似乎比它应该更复杂。

I have a feeling like I should know this, but I can''t think of anything. I''m trying to create a file management portion to my database (which tracks loans) so that every document that is associated with a particular loan will be readily accessible. My plan is to create a folder for each record using the PK as the folder name so that it can be found relatively easily using Windows Explorer. I would like for the folder to be created when the record is created. However, I can''t think of what to test for to know when the record gets created. I don''t want to check for the folder''s presense in the form''s AfterUpdate event as that will trigger frequently and there is no need to do so each time. I''m looking more for a NewRecordModified property. I suppose that I could use the form''s OnCurrent event to set a flag that the current record is a new record. Then in the form''s AfterUpdate event I could test to see if the flag is set to NewRecord and then create the folder. However, that seems more complicated than it should be.

推荐答案

在将记录插入表之前插入事件之前触发。

在将记录插入表中后插入事件触发后,除了自动编号字段之外的所有字段都已填充:
数据库对象的事件顺序(V2003)(对不起,刚刚实现这是一个较旧的链接;但是,我发现大部分活动顺序仍然有效。我现在必须找到一个V2010 :))无论如何,其中一个活动应该有所帮助。

如果您使用on current事件,则应检查您是否在新记录或现有记录中。
Before insert event fires before the record is even inserted into the table.
After insert event fires after the record has been inserted into the table, yet all but the autonumber fields have been populated:
Order of events for database objects (V2003) (Sorry, just realized this is an older link; however, I''ve found most of the event order is still valid. I''ll have to find a V2010 now :) ) In any case one of these events should help.
If you use the on current event then you should check if you are in a new record or an existing record.


自动编号字段甚至在BeforeUpdate事件之前显示该值。表单运行,所以即使它没有插入进入表格(让我感到惊讶),我仍然可以参考控件来获取价值。


你认为旗帜的想法很好吗?
The autonumber field displays the value even before the BeforeUpdate event of the form runs, so even if it hasn''t been inserted into the table (which surprises me), I can still reference the control to get the value.

So you think that the flag idea is a good one?


我对你的案子有点想法。

我会使用更新前事件。

向用户出示确认消息以确认更改。

你不需要一个标志来检查当前记录是否是新记录,你已经在表单属性中有这个( frm.NewRecord )如果是,那么运行子用于创建所需信息和文件夹等的代码...此时您应该能够在窗体中引用控件中的PK值。


这样,如果用户取消或中止然后没有新的文件夹。

如果记录是现有记录,那么你的条件不会运行代码来制作文件夹等......
I to think a tad on your case.
I would use the before update event.
Present a confirmation message to the user to confirm the changes.
You don''t need a flag to check to see if the current record is a new record, you already have that in the form properties (frm.NewRecord) and if so then run the sub-code to create the required information and the folder etc... You should be able to refer the value in the control for the PK on the form at this point.

This way, if the user cancels or aborts then no new folder.
If the record is an existing record then your conditional wont run the code to make the folder etc....


这篇关于如何在创建新记录时执行操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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