run a code on form A from form B

  • Thread starter Thread starter Sam
  • Start date Start date
S

Sam

how can i run the Form_Load code located in a opend form
from another form or from a module?

thanks
 
If you want to run the same code from more than one form, you should
really move that code into a public sub in a new or existing standard
module. The code within a form module, is really only for the use of
that form. You'll make it harder to debug your code, if the code in any
form can be arbitrarily called by other forms.

HTH,
TC [MVP Access]
 
Sam wrote in message said:
how can i run the Form_Load code located in a opend form
from another form or from a module?

thanks

I don't like calling event handlers, but would rather put the code into
a new sub within that forms class module or, if this code is so general
that it can be used with more than this form, place it in a standard
module.

Anyway - to call a sub or function located in a forms class module, it
needs to be declared as public, not private. Then just refer to it as
any other form/class property

call forms("frmMyForm").MySubName

You should be able to run the forms load code by using something like
this

call forms("frmMyForm").Form_Load

You should perhaps test whether to form is open first, and should it be
a subform you will need a more complete reference.
 
I agree with the others that it would probably make more sense to move the
code from the form's module to a common module. However, to be able to run
the code from another module, you need to change the declaration of the
routine from

Private Sub Form_Load()

to

Public Sub Form_Load()
 
Back
Top