How to open a record in a subform, starting in another form.

E

Eef

How to open a record in a subform, starting in another form.

The following procedure opens a form B (frm02_Aanvragers) on a specific
record.
The procedure is started on form A (frm01_Vrijwilligers)

Dim strDocName As String
Dim strLinkCriteria As String
Let strDocName = "frm02_Aanvragers"
Let strLinkCriteria = "[AanvragerId]=" & Me![AanvragerId]
DoCmd.OpenForm strDocName, , , strLinkCriteria

On form A exists AanvragerId but also ItemId.
On form B is a subform C with Items (ItemId) linked to AanvragerId.

Is it possible, starting on form A, not only to open form B with the
procedure above, but next
tot find a record in subform C, corresponding with the ItemId from form A?

Eef Houniet
 
E

Evi

You could use OpenArgs to do this. Add to the code in Form A

Dim MyItem As Long

MyItem = Me.ItemID

keep the line below but add MyItem in the OpenArgs position

DoCmd.OpenForm strDocName, , , strLinkCriteria,,,MyItem


In Form B, in the On Open event put

Dim rs As Object
If Not IsNull(Me.OpenArgs) Then
Set rs = Me.YourSubsName.Form.Recordset.Clone
rs.FindFirst "[ItemID]=" & Me.OpenArgs
Me.YouSubsName.Form.Bookmark = rs.Bookmark
Set rs = Nothing
End if

End Sub

subsitute YourSubsName with the real thing

Evi
 

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