Recalc Parent Form Without Losing Focus From The C

2019-08-30 22:52发布

问题:

In access database I have a Main Form with a Tabular SubForm. I want each of the Main Form's control being recalculated upon changing any value of any record of the Sub Form. I tried applying something like (me.parent.recalc) to each of the subform's control but found that now when I change "any" of the subform's record the focus would offset to the same field of subform's first record. Any solution? Regards

回答1:

Assuming your sub form control on the main form is named ctlSubForm, this would be a code sample you call in the subform, for example in an AfterUpdate event procedure:

'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


回答2:

Try me.parent.recordset.requery That should refresh only underlying recordset, not the form itself. I am not shure 100% about syntax but I use that approach in my Access projects.



标签: access-vba