首页 > 解决方案 > 重新计算父表单,而不会从子表单的当前记录中失去焦点

问题描述

在访问数据库中,我有一个带有表格子表单的主表单。我希望在更改子窗体的任何记录的任何值时重新计算主窗体的每个控件。我尝试将(me.parent.recalc)之类的东西应用于每个子表单的控件,但发现现在当我更改子表单的“任何”记录时,焦点将偏移到子表单第一条记录的同一字段。有什么解决办法吗?问候

标签: vbams-access

解决方案


假设您在主窗体上的子窗体控件名为ctlSubForm,这将是您在子窗体中调用的代码示例,例如在AfterUpdate事件过程中:

'Store the current sub forms record/bookmark
Dim currentRecord As Variant
currentRecord = Me.Bookmark

'Requery the main form, causing the first record of subform will be selected
'(instead place your existing code here)
Me.Parent.Requery

'Set the sub forms record/bookmark to the stored record/bookmark
Me.Bookmark = currentRecord

'Set the focus to the main forms sub form control
'(this is necessary to really get the focus back to the subform)
Me.Parent.ctlSubForm.SetFocus

推荐阅读