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