Call a function in another form's module?

  • Thread starter Thread starter Max Moor
  • Start date Start date
M

Max Moor

Hi All,
I have a form that sometimes pops up another form. It would be nice
to have both of these forms able to create a record in a certain table.
Can I define the function that does this in the main form, and then have
the popup call that one, or do I need to define the function in each
module?
If I can do it just in the main form, can I reference it with the
Parent property? I imagine that would be the proper way to do it, but I'm
not having a lot of luck using it. The proper syntax would be appreciated.

- Max
 
Max Moor said:
Hi All,
I have a form that sometimes pops up another form. It would be
nice to have both of these forms able to create a record in a certain
table. Can I define the function that does this in the main form, and
then have the popup call that one, or do I need to define the
function in each module?

You can define it in just the main form's module, so long as you define
it with the Public keyword. Any calls to it from outside that form,
though, will have to be qualified by a reference to that form; e.g.,

Call Forms!MainFormName.TheFunctionName
If I can do it just in the main form, can I reference it with the
Parent property? I imagine that would be the proper way to do it,
but I'm not having a lot of luck using it. The proper syntax would
be appreciated.

If this second form is a standalone form that is opened by the "main
form", then it's not really a subform and it won't have a Parent
property. If it were a true subform, then you could use its Parent
property as a reference to the main form, and say:

Call Me.Parent.TheFunctionName
 
I believe you also can use this syntax (with the function being Public):

Call Form_MainFormName.TheFunctionName

Works the same for a subroutine.
 
Ken Snell said:
I believe you also can use this syntax (with the function being
Public):

Call Form_MainFormName.TheFunctionName

Works the same for a subroutine.

Yes, but ISTR that there are some potential issues with that syntax:

1. If the form is not open, the call will open the form.

2. If there's more than one instance of the form open, you're not sure
which one is being called.
 
I believe you also can use this syntax (with the function being
Yes, but ISTR that there are some potential issues with that syntax:

1. If the form is not open, the call will open the form.

2. If there's more than one instance of the form open, you're not sure
which one is being called.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
Ah, yes, both are true statements!
 
Back
Top