Open form and show specific record in subform (1 Viewer)

brother

Programmer
Local time
Today, 13:37
Joined
Mar 30, 2009
Messages
40
Hi,

I have a form named Form1 with a subform Form2.
How can I open Form1 from another form and find a specific record in the subform?

This code only filters by customer, and not project like I want it to.
Code:
docmd.OpenForm "FrmProject",,,"[CustomerID]=forms![FrmMain].form![CustomerID]"


Hope that was not too confusing :p

Thanks!
 

HiTechCoach

Well-known member
Local time
Today, 06:37
Joined
Mar 6, 2006
Messages
4,357
On eoption would be to pass the record id as an OpenArg parameter.

In the Form's On Load event, check for the OpenArg. If found, then select that record in the sub form.
 

brother

Programmer
Local time
Today, 13:37
Joined
Mar 30, 2009
Messages
40
Thanks HiTechCoach!

To anyone who is looking for the same thing, here is my solution:

The button btnProject on FrmMain has the following Event:
Code:
docmd.OpenForm "FrmProject",,,"[CustomerID]=forms![FrmMain].form![CustomerID]",,[ProjectID]

In the OnLoad event of FrmProject I have written this code:
Code:
Private Sub Form_Load()
If Not IsNull(Me.OpenArgs) Then
Me.FrmProjectSub.SetFocus
Me.FrmProjectSub.Form!ProjectID.SetFocus
DoCmd.FindRecord Me.OpenArgs
End If
End Sub
 

HiTechCoach

Well-known member
Local time
Today, 06:37
Joined
Mar 6, 2006
Messages
4,357
brother,

Great job!

Glad we could assist.

Thanks for posting your solution so many other can benefit!
 

Users who are viewing this thread

Top Bottom