GoToRecord in a subform

  • Thread starter Thread starter Guest
  • Start date Start date
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!
 
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
 
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
 
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
 
Back
Top