I have a main form, frmItemDetail. This form has a subform frmStageSub in datasheetview. Nested within this form is another subform called frmCategorySub in Continuous Forms view. See attached pic.
On the main form, there are 6 calculated controls, Dsums, Dlookups etc.
frmStageSub and frmCategorySub both have calculated controls.
When I update either subform, I have the whole form recalc after update. I used recalc because supposedly it doesn't requery the underlying tables and shouldn't cause the current record to lose focus. However, I have found that this is not the case. When I update either subform, it takes me back to the first record in frmStageSub. For the record, I have tried Refresh and Requery as well. The results seem to be the same for all three.
Ideally I wish I could simply requery, recalc or refresh individual controls instead of the entire form, but this doesn't seem to work. I know controls support requery, but even when requerying an individual control it seems to requery the whole form.
I managed to get it to return to the same record when updating frmStageSub using this code that I have adapted from other discussions on the forum:
However, no matter what I do, I can't get it to return to the current record when I update the nested subform frmCategorySub.
As a side note, when the recalc runs, it appears to repaint or redraw the entire form 3 times. It looks like it recalcs the main form, then the first sub from top to bottom and then the nested sub from top to bottom. I think this may be a contributing factor in why I am having difficulty. This is why I included the Me.Painting lines.
Does anyone have any ideas for how I can correct this?
Thanks
On the main form, there are 6 calculated controls, Dsums, Dlookups etc.
frmStageSub and frmCategorySub both have calculated controls.
When I update either subform, I have the whole form recalc after update. I used recalc because supposedly it doesn't requery the underlying tables and shouldn't cause the current record to lose focus. However, I have found that this is not the case. When I update either subform, it takes me back to the first record in frmStageSub. For the record, I have tried Refresh and Requery as well. The results seem to be the same for all three.
Ideally I wish I could simply requery, recalc or refresh individual controls instead of the entire form, but this doesn't seem to work. I know controls support requery, but even when requerying an individual control it seems to requery the whole form.
I managed to get it to return to the same record when updating frmStageSub using this code that I have adapted from other discussions on the forum:
Code:
Me.Painting = False
Dim StgID As Long
StgID = Me.StageID
Me.Parent.Recalc
With Me.RecordsetClone
.FindFirst "StageID = " & StgID
Me.Bookmark = .Bookmark
End With
Me.Painting = True
As a side note, when the recalc runs, it appears to repaint or redraw the entire form 3 times. It looks like it recalcs the main form, then the first sub from top to bottom and then the nested sub from top to bottom. I think this may be a contributing factor in why I am having difficulty. This is why I included the Me.Painting lines.
Does anyone have any ideas for how I can correct this?
Thanks
Attachments
Last edited: