Execute code on subform from main form

  • Thread starter Thread starter tracey
  • Start date Start date
T

tracey

Does anyone know how I can run code that resides in a
subform from a button on the main form. I tried "Forms!
[FormName].ProcedureName" ; This worked in the reverse
situation however not in this situation.
 
This is because the subform is not per se open at all as a form. It is
buried in a control on the main form and is not visible in the Forms collection.
Generally, I'd argue that any reusable code should be placed in a public
procedure outside of the form module, so that no cumbersome addressing
be required.
In this case, maybe something like this would work (I never tried):

Me.Subformname.Procedurename
or
Forms!FormName.SubformControlName.Form.Procedurename

Pavel
 
I think (not tested) that you can use

FormName.Procedurename

The procedure must be a public procedure and not a Private one.

Pavel said:
This is because the subform is not per se open at all as a form. It is
buried in a control on the main form and is not visible in the Forms collection.
Generally, I'd argue that any reusable code should be placed in a public
procedure outside of the form module, so that no cumbersome addressing
be required.
In this case, maybe something like this would work (I never tried):

Me.Subformname.Procedurename
or
Forms!FormName.SubformControlName.Form.Procedurename

Pavel
Does anyone know how I can run code that resides in a
subform from a button on the main form. I tried "Forms!
[FormName].ProcedureName" ; This worked in the reverse
situation however not in this situation.
 
Back
Top