Set the RecordSource of that Form to a Query that returns the entire
recordset you want. Pass the unique identifier of the record you want in the
OpenArgs argument of the DoCmd.OpenForm statement you use to open the form.
In the OnOpen or OnLoad event, put code to use the passed value to do a
FindFirst on the RecordsetClone of the Form, then if the NoMatch property is
False, set the Form's Bookmark property to the Bookmark property of the
RecordsetClone.
Here's sample code for the DoCmd.OpenForm:
Dim stDocName As String
stDocName = "tblEmployees"
DoCmd.OpenForm stDocName, , , , , , Me![Combo0]
Here's corresponding sample code for the Form_Open event of the second Form:
If Len(Me.OpenArgs) > 0 Then
Me.RecordsetClone.FindFirst "[EmployeeNo] = " & Me.OpenArgs
If Not Me.RecordsetClone.NoMatch Then
Me.Bookmark = Me.RecordsetClone.Bookmark
Else
MsgBox "The record you requested was not found; opened at first
record"
End If
End If
It's not complete with error handling, but it's not air code.
I just realized it's linking to the correct subform (via [ref #])
within the main form but not the correct form (Profit Tracking 2). If i
can get it to direct to the [ref link] field in the [Profit Tracking 2]
form then this should work correctly. can you suggest anything else?
Thanks
Hi John, the brackets worked great. not the correct form opens up but
it's not linking to the correct record. i looked into the the form that
should link and the linking field is actually called [ref link]. i
tried inserting that in both spots in the code and again the correct
form opens up but the records aren't linking. btw [ref link] is a text
field and [ref # ] is an autonumber field .
Thanks
Steve
The space+underscore at the end of the first line is the VBA line
continuation character: it causes the two lines to be treated as one.
Have you tried enclosing the field name and table name in brackets,
e.g.
...DLookup("[send to Accting and print inv]", ...
Is the name of the field in the [Full Air Quote] table actually [send
to
Accting and print inv] ? (Life is simpler without all these spaces in
names!)
Is the [Ref # ] field a number (as its name indicates) or a text field?
If the latter, you need to use apostrophes or quotes to enclose it,
e.g.
..., "[Ref # ]='" & Me.Controls("Ref # ").Value & "'")
On 14 Jan 2006 13:42:38 -0800, "
[email protected]"
Reply