call sub from other module

J

Jesper

If I have a private sub in form1:

Private Sub cmdOK_click()
End sub

And I want to run this from within form2's module - is that possible?
Or must I make it public as:

Public Sub cmdOK_click()
End sub

Or should I just put the content of it in a public sub and run that from
where ever I need it?

Public sub myOKcode()
End sub


Thanks,
Jesper
 
D

Douglas J. Steele

While you can make it public, and then refer to the form when calling the
routine:

Call Form_Form1.cmdOK_Click()

you're probably better off putting it in a module, rather than associating
it with a form. Remember that Form1 would have to be open in order for you
to be able to call its code.
 
K

Klatuu

You can do it by referencing the form the sub is in:
Call Forms!form1.cmdOK_click()

However, I would suggest you put the code in a standard module and make it
public. Then, as you noted, you can call it from anywhere.
 
J

Jesper

While you can make it public, and then refer to the form when calling the
routine:

Call Form_Form1.cmdOK_Click()

you're probably better off putting it in a module, rather than associating
it with a form. Remember that Form1 would have to be open in order for you
to be able to call its code.

Great, thanks!
 
Top