How to use FindNext on subform

  • Thread starter Thread starter Lloyd
  • Start date Start date
L

Lloyd

I am trying to search a subform on another tab when a user exits a field to
check for a condition. I'm having trouble with the proper way to refer to
the form and field? I am trying to search the PersonType filed on the
subform subfrmPersonsUpdate. The below code is giving me an error saying it
can not find the form subformPersonUpdate.....I have tried a variety of ways
to refer to the form, but none of them seem to work. Can anyone tell me what
I am doing wrong with refering to the subform/field?

thanks


With Me.RecordsetClone
Select Case Me.CaseType

Case "Murder"

Forms![subfrmPersonsUpdate]!DoCmd.FindNext
"PersonType='Suspect'"

If Not IsNull(PersonType) Then Exit Sub
If .NoMatch Then

do something

End If

End Select
End With
 
There are several problems with your code. I assume in the code below your
subform is on the current form. One thing I can't tell from your code is
whether subfrmPersonsUpdate is the name of the subform control on the main
form or if it is the name of the form being used in the subform control. It
has to be the name of the subform control, not the name of the form being
used as the subform.

Also, you probably really want the FindFirst rather than the FindNext

With Me.subfrmPersonsUpdate.Form.RecordsetClone
Select Case Me.CaseType

Case "Murder"
.FindNext "[PersonType] = ""Suspect"""
If .NoMatch Then
Do Something
End If

End Select
End With
 
Thanks for your help. You were right, I did have the wrong subform control.
I'm still learning....I was looking at the form on the tab named
subfrmPersonsUpdate, but when I looked closer, the control name was
subfrmPersons. I made the change and it works fine now.

thanks again for the help, been trying to figure this out for several days.

Klatuu said:
There are several problems with your code. I assume in the code below your
subform is on the current form. One thing I can't tell from your code is
whether subfrmPersonsUpdate is the name of the subform control on the main
form or if it is the name of the form being used in the subform control. It
has to be the name of the subform control, not the name of the form being
used as the subform.

Also, you probably really want the FindFirst rather than the FindNext

With Me.subfrmPersonsUpdate.Form.RecordsetClone
Select Case Me.CaseType

Case "Murder"
.FindNext "[PersonType] = ""Suspect"""
If .NoMatch Then
Do Something
End If

End Select
End With
--
Dave Hargis, Microsoft Access MVP


Lloyd said:
I am trying to search a subform on another tab when a user exits a field to
check for a condition. I'm having trouble with the proper way to refer to
the form and field? I am trying to search the PersonType filed on the
subform subfrmPersonsUpdate. The below code is giving me an error saying it
can not find the form subformPersonUpdate.....I have tried a variety of ways
to refer to the form, but none of them seem to work. Can anyone tell me what
I am doing wrong with refering to the subform/field?

thanks


With Me.RecordsetClone
Select Case Me.CaseType

Case "Murder"

Forms![subfrmPersonsUpdate]!DoCmd.FindNext
"PersonType='Suspect'"

If Not IsNull(PersonType) Then Exit Sub
If .NoMatch Then

do something

End If

End Select
End With
 
Back
Top