GoToRecord in a subform

G

Guest

Hello,
I need a piece of code that will allow me to advance to records in a subform
of a subform (main form -> Subform1 -> Subform2, subform of Subform1). The
following works in Subform1 when it is not within the subform control of the
main form (code is in the Click event of a command button within subform1):
Subform2.setfocus
docmd.gotorecord , , acgoto , 2

Once I try this code from within the subform control of the main form, it no
longer works. Does anyone know of a way to correct this? I know that
subforms within subforms tend to complicate matters. Thank you for any help
you can provide!
 
K

kingston via AccessMonster.com

Create a Public subroutine in the main form that advances the record in
subform1 (or subform2). From within the other subform, call that subroutine
when you need it:

Forms!MainForm.PublicSub
 
M

Marshall Barton

Rebecca said:
I need a piece of code that will allow me to advance to records in a subform
of a subform (main form -> Subform1 -> Subform2, subform of Subform1). The
following works in Subform1 when it is not within the subform control of the
main form (code is in the Click event of a command button within subform1):
Subform2.setfocus
docmd.gotorecord , , acgoto , 2

Once I try this code from within the subform control of the main form, it no
longer works. Does anyone know of a way to correct this? I know that
subforms within subforms tend to complicate matters.


Another one of the problems with DoCmd nethods.

The general technique is to use methods of the form object's
Recordset or RecordsetClone.

This should be sufficient in newer versions of Access:

code in the form that you want to manipulate:
Me.Recordset.Move 2 'or MoveNext or FindFirst or . . .

code in the parent form of the subform:
Me.subform.Form.Recordset.Move 2

code in the grandparent form of the subsubform:
Me.subform.Form.subsubform.Form.Recordset.Move 2
 
G

Guest

Success!! This worked. Thank you!!

Marshall Barton said:
Another one of the problems with DoCmd nethods.

The general technique is to use methods of the form object's
Recordset or RecordsetClone.

This should be sufficient in newer versions of Access:

code in the form that you want to manipulate:
Me.Recordset.Move 2 'or MoveNext or FindFirst or . . .

code in the parent form of the subform:
Me.subform.Form.Recordset.Move 2

code in the grandparent form of the subsubform:
Me.subform.Form.subsubform.Form.Recordset.Move 2
 

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