如何从主表单中检测子表单事件? [英] How to detect a Sub-Form event from the Main Form?

查看:59
本文介绍了如何从主表单中检测子表单事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有SubForm的Access表单(MainForm)。我想知道是否存在检测SubForm记录更改的MainForm 事件


我可以使用On Current用于检测MainForm记录何时更改的事件,但是执行诸如On SubForm On Current之类的事件。存在吗?


非常感谢,

I have an Access form (MainForm) that has a SubForm. I would like to know if a MainForm event exists that detects a SubForm record change.

I can use the "On Current" event to detect when the MainForm record changes, but does an event such as "On SubForm On Current" exist?

Many thanks,

推荐答案

嗨。这是子窗体的On Current事件,它会触发子窗体中的每条记录。主窗体无法接收或处理子窗体的事件。如果您希望使用此事件,则必须将代码放在子窗体中。


虽然从技术上讲可以为主窗体的子窗体设置自定义事件处理程序可以听这不是一项微不足道的任务。我没有用主表单/子表单组合尝试这个,所以我不能肯定地说甚至可以使用这种方法。自定义事件处理程序可以很好地用于独立表单。


如果您希望调用表单代码模块范围之外的子例程或函数(在本地范围内是即使在主窗体/子窗体组合中,相关的代码也可能需要将相关代码放在公共代码模块中(即数据库窗口的模块选项卡中显示的代码)。然后,您可以根据需要从相关的On Current事件处理程序中调用代码。


-Stewart
Hi. It is the subform''s On Current event that fires for each record in the subform. The main form cannot receive or handle the subform''s events. If you wish to use this event you have to place the code in the subform itself.

Whilst it may technically be possible to set up custom event handlers for your subform to which the main form could listen this is not a trivial task. I have not tried this with a main form / sub form combination so I cannot say for sure that it is even possible to use this approach. Custom event handlers can work well for independent forms.

If you wish to call subroutines or functions outside of the scope of your form''s code modules (which are local in scope to the form concerned and not visible to any other form, even in mainform/subform combinations) you will need to place the code concerned in a public code module (i.e. one that is shown in the Modules tab of the database window). You can then call the code as necessary from the relevant On Current event handler.

-Stewart


感谢您的帮助...在尝试中为了实现解决方案,我遇到了一个相关问题,这将涉及更多解释...


MainForm有两个子表单,SubForm1和SubForm2。

当SubForm1中的记录发生变化时,我想在SubForm2中显示不同的记录。


我几乎可以通过在SubForm1的Form_Current事件中使用以下代码来实现这一点br />
Thanks for your help...In trying to implement a solution, I encountered a related problem, which will involve some more explanation...

MainForm has two sub-forms, SubForm1 and SubForm2.

When the record in SubForm1 changes, I want to display different records in SubForm2.

I can almost achieve this by using the following code in the Form_Current event of SubForm1

展开 | 选择 | Wrap | 行号


嗯,除非你有某种形式的自动选择,哪个子窗体作为主窗体的一部分加载,否则如果主窗体是子窗体必须存在的情况总是如此?


无论如何,没有内置函数检查正在加载的子窗体,但是如果命名子窗体控件出现在主窗体上,则以下简单自定义函数返回true,否则返回false。我确实认为这是一个冗余检查。

Hmm, unless you have some form of automated selection of which subform is loaded as part of the main form, wouldn''t it always be the case that the subform must be present if the main form is?

Anyway, there is no built-in function that checks for the subform being loaded, but the following simple custom function returns true if the named subform control is present on the main form and false otherwise. I really do think this is a redundant check, however.

展开 | 选择 | Wrap | 行号


这篇关于如何从主表单中检测子表单事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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