Finding a record from a subform on mainform

mhubbard

Registered User.
Local time
Today, 14:47
Joined
Jul 31, 2002
Messages
25
I have a main form 'TS PM Filter' and a Subform 'getcurrentusers'
On the subform, I have a number of fields including 'Personid'. What I am trying to do is when the 'find record button' is pressed(on subform) the main form opens and finds the 'personid' from the subform. Below is the code I am using but it just goes to the first record on the mainform

Private Sub Command45_Click()
Dim stDocName As String

Dim stLinkCriteria As String

stDocName = "TS PM Filter"

stLinkCriteria = Me!Personid

DoCmd.OpenForm stDocName, , , Trim(stLinkCriteria)
DoCmd.Close acForm, "getcurrentusers", acSaveNo


End Sub

Any help would be huge.
Thank You!
 
You have to add the full WHERE expression for the filter.

Instead of...
stLinkCriteria = Me!Personid

Try

stLinkCriteria = "[Personid]=" & Me![Personid]
 
Thanks Fornatian.

Just two things:

It prompts me for the personid? Not sure how to get rid of it.
Also, it actually filters the record on the main form. Is there anyway to autamically turn the filter off

Thanks again for your help!
 
I suspect that yours does quote because on the target form there is no field/control named Personid, try changing it to the field name of the relevant field..

stLinkCriteria = "[WhateverField]=" & Me![Personid]
 

Users who are viewing this thread

Back
Top Bottom