2

如前所述,这是一个 Access 2010 .accdb。

我有一个主要的导航表单:frmNav。

在 frmNav 我有一个导航子窗体控件:NavigationSubForm。

我使用 docmd browseto 在导航控件的选项卡之间移动。

在 NavigationSubForm 控件中加载的第一个表单是 frmInboundShipments。

frmInboundShipments 包含一个子表单控件 sfrmListInvoicesByShipment。

sfrmListInvoicesByShipment 包含经过筛选的发票数据表,该数据表与 frmInboundShipments 中的每个货件相关联。

frmItemInvoices 包含 sfrmListInvoicesByShipment 中引用的发票。

以下使用 browseto 命令在 frmInboundShipments 和 frmItemInvoices 之间移动的方法触发 frmInboundShipments 上的 UnLoad 事件:

  1. 单击 frmInboundShipments 上的命令按钮以调用 browseto 到 frmItemInvoices
  2. 单击frmNav 上导航控件上的导航选项卡/按钮以调用browseto frmItemInvoices。

但是,当我执行以下操作时,frmInboundShipments 上的 UnLoad 事件无法触发

  1. 双击 sfrmListInvoicesByShipment 中的字段/数据表行以触发 browseto 命令以通过以下任一方式显示/移动到 frmItemInvoices:

    一个。立即执行 docmd browseto 以显示 frmItemInvoices

    湾。先将焦点设置在父窗体上,然后执行 docmd browseto 显示 frmItemInvoices

     i. e.g.: Me.Parent.sfrmListInvoicesByShipments.SetFocus
    
              DoCmd.BrowseTo acBrowseToForm, "frmItemInvoices", "frmNav.NavigationSubform", ...criteria....
    

我一生都无法理解为什么从子表单发出browseto命令时事件不会触发,而是在两个表单之间导航时在其他所有场景中触发。

我查看了 Access 2010 的事件顺序,我没有看到任何明确说明在从子表单查看另一个表单时不会触发主表单的 Unload 事件的任何内容。

在这种情况下也不会触发 Deactivate 事件。

更新,2013 年 10 月 18 日:进一步调查显示父窗体的 Close 事件确实触发,但绝对不是 deactivate 或 unload 事件。问题是一旦表单关闭事件发生,我想要捕获的值就已经消失了。不知道从这里做什么......

4

1 回答 1

0

rudelerius,

I feel your pain. I have had long experience debugging Access Form events, and have come away with several rules:

  1. Form events don't always fire when you expect them to.
  2. Form events do not always fire in a particular order, despite what the documentation may say.
  3. Finally, debugging by putting a Breakpoint in an event procedure can change the order or number of events that get fired.

So what can you do? My recommendations:

  1. Form events are for handling Form-level actions. They are just plumbing, and you should not overload them with Application-level functions
  2. Separate your Application or Business logic from your forms, and especially do not plug Business logic into any Form or Report Event. In other words, the code that supports what your application does should be separate from how it does it.
  3. For debugging, use things like Debug.Print in the event procedure, and avoid Breakpoints.

So, how does this help you? My (necessarily broad) answer is put whatever information you want to preserve in an external module-level variable, or class, before you take your form action. Your main form can then use that information without relying on the state of the child.

于 2015-04-13T21:34:26.070 回答