重新计算父窗体,而不会从子窗体的当前记录中失去焦点

时间:2019-03-16 07:36:11

标签: access-vba

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

2 个答案:

答案 0 :(得分: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

答案 1 :(得分:0)

尝试me.parent.recordset.requery 那应该只刷新基础记录集,而不刷新表单本身。我对语法没有100%的把握,但是我在Access项目中使用了这种方法。