Another GoToRecord

  • Thread starter Afrosheen via AccessMonster.com
  • Start date
A

Afrosheen via AccessMonster.com

Good morning. I have a form with a subfom on it. I use the subform as a
search box. When I enter the last name of the person the subform works the
way it should and looks up the record and displays it. What I'd like to do is
when I close the subform I would like the main form goto that record from the
information on the subform when I close the subform. I'm trying to use the
GoToRecord clause. Here is the code.

20 Me.Parent!cmdSave.SetFocus
30 Me.Parent!SubFrmFind.Visible = False
DoCmd.GoToRecord ([StaffId] = Text12)

The staffid is a text field. The text12 is just a text box that has the
staffid in it. The problem is that all it does is go to the next record not
the record I need.

When I tried using the DoCmd.FindFirst ([StaffId] = Text12) I got errors.

Thanks for your help and reply.
 
J

Jeff Boyce

A subform in Access is usually used to display records related to the record
in the main form.

If your focus is still in the subform (hint: your code uses "Me."), then
it's the subform's record source (does it even have one?!) that will be
used.

More info, please...

Regards

Jeff Boyce
Microsoft Access MVP

--
Disclaimer: This author may have received products and services mentioned
in this post. Mention and/or description of a product or service herein
does not constitute endorsement thereof.

Any code or pseudocode included in this post is offered "as is", with no
guarantee as to suitability.

You can thank the FTC of the USA for making this disclaimer
possible/necessary.
 
A

Afrosheen via AccessMonster.com

Thanks for your reply Jeff. I'll try and give you more detail.
Form "A" is the main form "frmRosterSub1" and form "B" is "SubFrmFind" that's
hidden until I press the cmdFind button. Once pressed, form "B" pops up and a
search can be performed on the last name. Once the correct last name and
person is displayed, I want to press the "Stop" button and have form "B" hide
and form "A" display the results of the search.

There is no parent/child link because when I do, the search will find no
records with the information I type in. The record source on both forms "A"
& "B" are the same.

This is the code to hide the form "B"

Private Sub cmdExit_Click()

20 Me.Parent!cmdSave.SetFocus
30 Me.Parent!SubFrmFind.Visible = False

DoCmd.GoToRecord ([StaffID] = Text12)

End Sub

Maybe I should take the "Me" out?
I hope this was the information you needed.

Jeff said:
A subform in Access is usually used to display records related to the record
in the main form.

If your focus is still in the subform (hint: your code uses "Me."), then
it's the subform's record source (does it even have one?!) that will be
used.

More info, please...

Regards

Jeff Boyce
Microsoft Access MVP
Good morning. I have a form with a subfom on it. I use the subform as a
search box. When I enter the last name of the person the subform works the
[quoted text clipped - 17 lines]
Thanks for your help and reply.
 
J

Jeff Boyce

No, I was pointing out that the focus may still be in the subform... so the
GoToRecord could be looking in the subform's record source, not the parent
form's record source.

Something you wrote gave me pause ...

When you say "pops up", does that mean what you're calling a "subform" is
actually a dialog box/modal form, and not strictly a subform embedded in the
main form?

Regards

Jeff Boyce
Microsoft Access MVP

--
Disclaimer: This author may have received products and services mentioned
in this post. Mention and/or description of a product or service herein
does not constitute endorsement thereof.

Any code or pseudocode included in this post is offered "as is", with no
guarantee as to suitability.

You can thank the FTC of the USA for making this disclaimer
possible/necessary.

Afrosheen via AccessMonster.com said:
Thanks for your reply Jeff. I'll try and give you more detail.
Form "A" is the main form "frmRosterSub1" and form "B" is "SubFrmFind"
that's
hidden until I press the cmdFind button. Once pressed, form "B" pops up
and a
search can be performed on the last name. Once the correct last name and
person is displayed, I want to press the "Stop" button and have form "B"
hide
and form "A" display the results of the search.

There is no parent/child link because when I do, the search will find no
records with the information I type in. The record source on both forms
"A"
& "B" are the same.

This is the code to hide the form "B"

Private Sub cmdExit_Click()

20 Me.Parent!cmdSave.SetFocus
30 Me.Parent!SubFrmFind.Visible = False

DoCmd.GoToRecord ([StaffID] = Text12)

End Sub

Maybe I should take the "Me" out?
I hope this was the information you needed.

Jeff said:
A subform in Access is usually used to display records related to the
record
in the main form.

If your focus is still in the subform (hint: your code uses "Me."), then
it's the subform's record source (does it even have one?!) that will be
used.

More info, please...

Regards

Jeff Boyce
Microsoft Access MVP
Good morning. I have a form with a subfom on it. I use the subform as a
search box. When I enter the last name of the person the subform works
the
[quoted text clipped - 17 lines]
Thanks for your help and reply.
 
A

Afrosheen via AccessMonster.com

No. It's actually a subform embedded on the main form. It's just hidden and
not visible.
frmsubfind.visible = false/true which ever is needed.

#1 me.parent!cmdfind.SetFocus
#2 Me.Parent!SubfrmFind.visible=false

#1 sets the focus to the main form on a command button
#2 sets the SubFrmFind.visible=false.

Those routines I got from Marshall Barton because I could not close the
subform.

Thanks for your help Jeff.

Jeff said:
No, I was pointing out that the focus may still be in the subform... so the
GoToRecord could be looking in the subform's record source, not the parent
form's record source.

Something you wrote gave me pause ...

When you say "pops up", does that mean what you're calling a "subform" is
actually a dialog box/modal form, and not strictly a subform embedded in the
main form?

Regards

Jeff Boyce
Microsoft Access MVP
Thanks for your reply Jeff. I'll try and give you more detail.
Form "A" is the main form "frmRosterSub1" and form "B" is "SubFrmFind"
[quoted text clipped - 46 lines]
 
J

Jeff Boyce

I'll step back, as I don't have any more ideas at this point.

Perhaps one of the other newsgroup readers can resolve this for you.

Regards

Jeff Boyce
Microsoft Access MVP

--
Disclaimer: This author may have received products and services mentioned
in this post. Mention and/or description of a product or service herein
does not constitute endorsement thereof.

Any code or pseudocode included in this post is offered "as is", with no
guarantee as to suitability.

You can thank the FTC of the USA for making this disclaimer
possible/necessary.

Afrosheen via AccessMonster.com said:
No. It's actually a subform embedded on the main form. It's just hidden
and
not visible.
frmsubfind.visible = false/true which ever is needed.

#1 me.parent!cmdfind.SetFocus
#2 Me.Parent!SubfrmFind.visible=false

#1 sets the focus to the main form on a command button
#2 sets the SubFrmFind.visible=false.

Those routines I got from Marshall Barton because I could not close the
subform.

Thanks for your help Jeff.

Jeff said:
No, I was pointing out that the focus may still be in the subform... so
the
GoToRecord could be looking in the subform's record source, not the parent
form's record source.

Something you wrote gave me pause ...

When you say "pops up", does that mean what you're calling a "subform" is
actually a dialog box/modal form, and not strictly a subform embedded in
the
main form?

Regards

Jeff Boyce
Microsoft Access MVP
Thanks for your reply Jeff. I'll try and give you more detail.
Form "A" is the main form "frmRosterSub1" and form "B" is "SubFrmFind"
[quoted text clipped - 46 lines]
Thanks for your help and reply.
 
M

Marshall Barton

Afrosheen said:
Thanks for your reply Jeff. I'll try and give you more detail.
Form "A" is the main form "frmRosterSub1" and form "B" is "SubFrmFind" that's
hidden until I press the cmdFind button. Once pressed, form "B" pops up and a
search can be performed on the last name. Once the correct last name and
person is displayed, I want to press the "Stop" button and have form "B" hide
and form "A" display the results of the search.

There is no parent/child link because when I do, the search will find no
records with the information I type in. The record source on both forms "A"
& "B" are the same.

This is the code to hide the form "B"

Private Sub cmdExit_Click()

20 Me.Parent!cmdSave.SetFocus
30 Me.Parent!SubFrmFind.Visible = False

DoCmd.GoToRecord ([StaffID] = Text12)

End Sub


GoToRecord does not work that way.

You should use the DAO FindFirst method something like:

With Parent.RecordsetClone
.FindFirst "StaffId = " & Text12
If Not .NoMatch Then
Parent.Bookmark = .Bookmark
Else
Beep
End If
End With

There is no FindFirst method for the DoCmd Object. There is
a DoCmd.FindRecord but it does not have a way to specify the
form you where want to find the record. In general, there
is a better way to do most of the DoCmd thingies so if you
think you want to use DoCmd, look for a different way.
 
A

Afrosheen via AccessMonster.com

You the man again. This is on the form you helped me with earlier in the week.
It works great. You've just made my life easier.

Thanks again.

Marshall said:
Thanks for your reply Jeff. I'll try and give you more detail.
Form "A" is the main form "frmRosterSub1" and form "B" is "SubFrmFind" that's
[quoted text clipped - 17 lines]

GoToRecord does not work that way.

You should use the DAO FindFirst method something like:

With Parent.RecordsetClone
.FindFirst "StaffId = " & Text12
If Not .NoMatch Then
Parent.Bookmark = .Bookmark
Else
Beep
End If
End With

There is no FindFirst method for the DoCmd Object. There is
a DoCmd.FindRecord but it does not have a way to specify the
form you where want to find the record. In general, there
is a better way to do most of the DoCmd thingies so if you
think you want to use DoCmd, look for a different way.
 
K

Kathy R.

Marshall said:
In general, there
is a better way to do most of the DoCmd thingies so if you
think you want to use DoCmd, look for a different way.

Marshal,

Thank you for the smile you just gave me. The help I have received on
these forums has been wonderful, patient, professional... and the list
goes on. Just looking at the collective knowledge of the folks that
answer questions around here sometimes makes me feel like quite ignorant
(but I continue to learn!). It's nice to know that, even the
professionals, talk about those "thingies!"

Kathy R.
 

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