MS Access form_current() 多次触发
我有一个带有两个子表单的表单(在单独的选项卡页上)。这是Access中的MDB项目 2003.
当它最初打开时,活动子窗体上的 Form_Current 会触发一次,如下所示 它应该。
但是当您移动到另一条记录(即从主窗体)时,它会触发 活动子窗体上的 Form_Current 4 次。然后随后的记录移动 导致 Form_Current 触发 2 次。这很痛苦,因为子表单 有很多字段被移动和/或隐藏,所以它会跳来跳去 每个 Form_Current,更不用说速度很慢了。
我通过 DoCmd.OpenForm 使用过滤器打开表单(实际上它发送 通过 OpenArgs 进行过滤)。 FilterOn 只设置一次,在 Form_Open 上 主窗体,从不在子窗体中。 Form_Current 未显式调用 代码中的其他任何地方。
当我在 Form_Current 第一次触发移动时查看调用堆栈时, 它看起来像:
my_subform.Form_Current
[<Debug Window>]
my_subform.Form_Current
所以看起来 Form_Current 中的某些内容正在触发另一个 Form_Current 事件。但仅限于第一个记录移动。
Form_Current中的代码有些复杂,涉及自定义类和 事件回调,但一般不触及表数据。我唯一的事 可以认为可能触发 Form_Current 的是它检查 OldValue 表单控件 - 这可能是导致它的原因吗?
或者还有其他想到的吗?
谢谢。
埃里克
I have a form with two subforms (on separate tab pages). It's an MDB project in Access
2003.
When it initially opens, Form_Current on the active subform fires once, as
it should.
But when you move to another record (ie. from the main form), it fires
Form_Current on the active subform 4 times. Then subsequent record-moves
result in Form_Current firing 2 times. This is a pain, because the subforms
have a lot of fields that get moved and/or hidden and so it jumps around for
every Form_Current, not to mention being slow.
I am opening the form with a filter via DoCmd.OpenForm (actually it sends
the filter in via OpenArgs). FilterOn is only set once, in Form_Open on the
main form, never in the subforms. Form_Current is not called explicitly
anywhere else in the code.
When I look at the call stack when Form_Current fires moving the first time,
it looks like:
my_subform.Form_Current
[<Debug Window>]
my_subform.Form_Current
So it seems like something in Form_Current is triggering another
Form_Current event. But only on the first record move.
The code in Form_Current is somewhat complex, involving custom classes and
event callbacks, but generally does not touch the table data. The only thing I
can think might be triggering a Form_Current is that it checks OldValue on
form controls - could this be causing it?
Or anything else come to mind?
Thanks.
Eric
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如 TheAceMan1 曾经指出的那样,“对于 On Current 事件,您唯一需要注意的是递归!也就是说……事件中的代码会导致事件重新触发。就像移动到代码中的另一条记录一样。除了……活动的规模可以根据需要而定。”我发现 Current 非常紧张。也就是说,有时它是放置代码的唯一位置。
您可能知道子表单的事件先于父表单的事件触发。对于负载来说确实如此,对于电流来说也许也是如此。
我只能建议逐步排除故障;注释掉零件,检查功能并解决它。当然,您随时可以发布更多代码供我们查看。
As TheAceMan1 once noted, "The only thing you have to watch out for with the On Current event is recursion! That is ... code in the event that causes the event to retrigger. Like moving to another record within the code. Other than that ... the event can be as hefty as required." I have found Current to be horribly twitchy. That said, it is sometimes the only place to put your code.
You may be aware that events for sub-forms trigger before those for the parent form. This is certainly true for Load, and maybe for Current as well.
I can only suggest step-by-step trouble-shooting; comment out parts, check functioning, and work it out. Of course you can always post a heap more code for us to see.