There are two main approaches: (1) let code behind the form do most of
the work, or (2) do the work at the point where you open the form. Here
are very simplified forms of both:
(1) The form does the work.
Where you open the form:
Dim lngRecordID As Long
' ... set lngRecordID to the key you want to find ...
DoCmd.OpenForm "MyForm", OpenArgs:=lngRecordID
In the form's Load event:
Private Sub Form_Load()
Dim strRecordToFind As String
strRecordToFind = Me.OpenArgs & ""
If Len(strRecordToFind) <> 0 Then
With Me.RecordsetClone
.FindFirst "ID=" & strRecordToFind
If Not .NoMatch Then
Me.Bookmark = .Bookmark
End If
End With
End If
End Sub
(2) Caller does the work (no special code in form)
Dim lngRecordID As Long
Dim frm As Form
' ... set lngRecordID to the key you want to find ...
DoCmd.OpenForm "MyForm"
Set frm = Forms("MyForm")
With frm.RecordsetClone
.FindFirst "ID=" & strRecordToFind
If Not .NoMatch Then
frm.Bookmark = .Bookmark
End If
End With
Set frm = Nothing
--
Dirk Goldgar, MS Access MVP
www.datagnostics.com
(please reply to the newsgroup)