Execute a function from different form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is it possible in the code of a main form to call a function that is coded on
a subform that belongs to the main form? Reason being that conditions need
to be checked from both places, possibly several times in the subform and
once when exiting the main form.
 
Yes, this can be done. Declare that function in the subform as a Public
Function.

Then call it (subform must be open on its own or as part of the main form
that is calling the function):
Call Form_NameOfSubformForm.NameOfFunction
 
How about putting the function in a module? That way there is no problem with
which forms are open or not?

Ken Snell said:
Yes, this can be done. Declare that function in the subform as a Public
Function.

Then call it (subform must be open on its own or as part of the main form
that is calling the function):
Call Form_NameOfSubformForm.NameOfFunction
 
That can be done as well.

Typically, I often call subform event procedures from a main form when doing
data updates via code, so I just use what is already there.
--

Ken Snell
<MS ACCESS MVP>

Klatuu said:
How about putting the function in a module? That way there is no problem
with
which forms are open or not?
 
Ken said:
Yes, this can be done. Declare that function in the subform as a Public
Function.

Then call it (subform must be open on its own or as part of the main form
that is calling the function):
Call Form_NameOfSubformForm.NameOfFunction


A more specific way to call it:

Me.subformcontrol.Form.NameOfFunction

It wouldn't make any difference which instance of the class
you call unless the function has Static variables or it uses
module level variables.
 
My first thought was to put the code in a module, but the fields being
checked for values are bound to the subform anyway, so it would have to be
open regardless. Thanks for your input. It has helped greatly.
 
Back
Top