Resyncing a subform record

K

Kurt

The following code comes from FMS as a Tip.

In order to make this code work, does this code get placed in the subform or
main form?

On what event of what form (Main or subform) should this procedure be
called?
=======================================================================

Resyncing a subform record
Provided by: Luke Chung, FMS President
When the master record is updated, the subform resets itself to the first
record. It would be preferable to keep the record pointer at the same
subform record. The solution is very simple. Get the ID identifying the row
that should be the current one. Use this ID value to search on the
RecordsetClone and use the bookmark property to resync your subform record.

Sub ResyncSubformRecord(strSubformName As String, strFieldName As String,
lngID as Long)

' Comments: Update a subform to make a specific record the current one
' In : strSubformName - Name of subform with data to resync
' strFieldName - Field to specify the search criteria
' lngID - ID value in the field to find (usually

' the primary key value)

Dim rst As DAO.Recordset

Set rst = Me(strSubformName).RecordsetClone

rst.FindFirst "[" & strFieldName & "] = " & lngID

If Not rst.NoMatch Then

Me(strSubformName).Bookmark = rst.Bookmark

End If

rst.Close

End Sub
 
D

Douglas J. Steele

It would go on the Parent form.

What event depends on when you want it to fire. As the tip suggests, you
need it when the master record is updated, so calling that routine from the
parent form's AfterUpdate event would be a good place to start.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top