R
RobGMiller
Access 2003,
When a form containing a subform is opened it must set the content of a
control on the parent form to link the SubForm\Subreport control Parent and
child fields, then it sets the Subform Filter and OrderBy. Then it must find
a record and move to that record. The parent form is unbound and the subform
is bound to a table.
All this code is in the parent form onOpen event and it all works well. The
record is found and you can see the pointer on the record selectors moving to
the correct record as the form opens but then it moves back to the first
record.
My guess is that the form is somehow refreshed after the pointer is moved.
In the parentform.OnOpen event the code is performed in the following
summarized manner.
Me!ParentChildLinkControlName = "xxx"
Me.SubformContainer.Form.Filter = "ColumnX = 'Data'"
Me.SubformContainer.Form.OrderBy = "fieldname asc"
Set rst = frm.Recordset
rst.FindFirst "Reference = '" & Data & "'"
If Not rst.NoMatch Then frm.Bookmark = rst.Bookmark
Set rst = Nothing
This is pretty straight forward.
I've tried it in the OnLoad and OnOpen of the parent form as well as the
subForm.
I've tried it as part of the code that opens the parent form using a button
in a different form.
I've tried putting the filtering and sorting in the form and ran the code to
find the record outside the form after it opens.
If there is no filtering the Bookmark section does move to the correct
record and stay there. This does not work if the Bookmark code is outside the
form but it does work from the OnOpen event of the parent form.
Can someone tell me if the method is sound in this case. If not, where can
the filtering stuff be put so that everything is stable by the time the
bookmark is set.
Thanks in advance for your help.
When a form containing a subform is opened it must set the content of a
control on the parent form to link the SubForm\Subreport control Parent and
child fields, then it sets the Subform Filter and OrderBy. Then it must find
a record and move to that record. The parent form is unbound and the subform
is bound to a table.
All this code is in the parent form onOpen event and it all works well. The
record is found and you can see the pointer on the record selectors moving to
the correct record as the form opens but then it moves back to the first
record.
My guess is that the form is somehow refreshed after the pointer is moved.
In the parentform.OnOpen event the code is performed in the following
summarized manner.
Me!ParentChildLinkControlName = "xxx"
Me.SubformContainer.Form.Filter = "ColumnX = 'Data'"
Me.SubformContainer.Form.OrderBy = "fieldname asc"
Set rst = frm.Recordset
rst.FindFirst "Reference = '" & Data & "'"
If Not rst.NoMatch Then frm.Bookmark = rst.Bookmark
Set rst = Nothing
This is pretty straight forward.
I've tried it in the OnLoad and OnOpen of the parent form as well as the
subForm.
I've tried it as part of the code that opens the parent form using a button
in a different form.
I've tried putting the filtering and sorting in the form and ran the code to
find the record outside the form after it opens.
If there is no filtering the Bookmark section does move to the correct
record and stay there. This does not work if the Bookmark code is outside the
form but it does work from the OnOpen event of the parent form.
Can someone tell me if the method is sound in this case. If not, where can
the filtering stuff be put so that everything is stable by the time the
bookmark is set.
Thanks in advance for your help.