How to use FindNext on subform

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
 
K

Klatuu

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
 
L

Lloyd

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
 

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