Recalc父母表格不会从当前的SubForm记录中丢失焦点

问题描述 投票:0回答:2

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

access-vba
2个回答
0
投票

假设您在主窗体上的子窗体控件名为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

0
投票

试试me.parent.recordset.requery这应该只刷新底层记录集,而不是表单本身。我不是100%关于语法,但我在我的Access项目中使用该方法。

© www.soinside.com 2019 - 2024. All rights reserved.