keep subforms in sync

  • Thread starter Thread starter mcnews2k
  • Start date Start date
M

mcnews2k

i have a form with 2 datasheet subforms.
one is bound to a query of a table of duplicate records.
the other is bound to a query of the main table where the original records
are found.
the main form containing the tables allows users to view both recordsets and
decide which one to keep by checking a check box on the dupe subform.

my question is how to best keep the subforms in sync.
all i want to happen is when i navigate through the records on the top
subform the record pointer on the second form moves in sync with the first
and vise versa.

how to?

thanks much.
 
mcnews2k said:
i have a form with 2 datasheet subforms.
one is bound to a query of a table of duplicate records.
the other is bound to a query of the main table where the original
records are found.
the main form containing the tables allows users to view both
recordsets and decide which one to keep by checking a check box on
the dupe subform.

my question is how to best keep the subforms in sync.
all i want to happen is when i navigate through the records on the top
subform the record pointer on the second form moves in sync with the
first and vise versa.

how to?

thanks much.

I'm not sure what you mean. Is this a case where you want the bottom
subform to show only the record(s) that correspond to the current record
in the top subform, or is the bottom subform supposed to show multiple
records of which only one (which you want to become current) corresponds
to the current record on the top subform?
 
both subforms should have pretty much the same number of records.
if i move the record navigator to record 2 in the top subform the
record navigator moves to record 2 in the bottom subform and vise
versa.

what i've done instead is bind the query for the bottom subform to the
main form then link both subforms to a field on the main form and use
the record navigator of the main form to navigate through the records.

this will suffice, but would still like to know how to do what i asked
originally.

thanks,
mcnews
 
mcnews said:
both subforms should have pretty much the same number of records.
if i move the record navigator to record 2 in the top subform the
record navigator moves to record 2 in the bottom subform and vise
versa.

what i've done instead is bind the query for the bottom subform to the
main form then link both subforms to a field on the main form and use
the record navigator of the main form to navigate through the records.

this will suffice, but would still like to know how to do what i asked
originally.

thanks,
mcnews

It's not clear to me what represents synchronization of the two
subforms, but if you can define that you can certainly use code in the
Current event of the top subform to reposition the bottom subform. For
example, if both subforms have records with the same key fields, such
that you want the bottom subform to show the record with the same key as
the top subform, then you might use code along these lines (assuming
subform control names "sfTop" and "sfBottom"):

'---- start of example #1 code for sfTop ----
Private Sub Form_Current()

If Me.NewRecord Then
' not sure what to do here
Exit Sub
End If

Me.Parent!sfBottom.Form.Recordset.FindFirst _
"KeyField = " & Me.KeyField

End Sub
'---- end of example #1 code for sfTop ----

If, on the other hand, you just need the bottom subform to be positioned
to the same "record number" as the top subform -- bearing in mind that
these "record numbers" are dependent on the sort sequence imposed on the
forms' recordsources, and are entirely arbitrary in the absence of such
ordering -- then you might use code along these lines:

'---- start of example #2 code for sfTop ----
Private Sub Form_Current()

If Me.NewRecord Then
' not sure what to do here
Exit Sub
End If

Me.Parent!sfBottom.Form.Recordset.AbsolutePosition = _
Me.Recordset.AbsolutePosition

End Sub
'---- end of example #2 code for sfTop ----

Note that the above will only work if the two subforms have the same
number of records. Note also that all of the above code is untested
"air code".
 
Back
Top