Making private sub globally visible

mcdhappy80

Registered User.
Local time
Today, 14:32
Joined
Jun 22, 2009
Messages
347
I've created a private procedure on one button on one form in my application.
Can I make that procedure globally visible (usable on other buttons in other forms in the application - OO approach), and how?
Where do I put it and how should I declare it and call (instantiate) it?
Thank You
 
The best thing is to put it into a standard module as Public. You can change it to Public in your form's module, but you will need to call it like

Forms!YourFormName.YourProcedure

But be aware that if you do that, it will open an instance of your form in hidden view. That is why I would move it to a standard module.
 
I've copied it in another class module as a public sub.
Now I have two problems.

1) From within the sub, that was part of a forms class module, I'm referencing one text field on one particular form in application. Now when I copied it to separate module, that reference is gone.
Can I somehow make procedure more universal by being able to pass, as an argument, which control on which form should it use the value from needed for its calculations?
How do I do it?
Is there some other way to do this?

2) How do I actually call the procedure now, when it is not part of a class module anymore and not bound to the buttons click event?

Thank You
 
If the code you're writing is form specific, why do you want to publicize it?

What you can do is, generalize the code to accept any text field in general, then throw it in a module
 
I didn't say to put it in a class module. Put it in a STANDARD module.

Then you can pass it like this:

Code:
Public Function Test(frm As Form) 
   frm.PropertyOrMethodHere = "Whatever"
End Function

And call it like this:

Test Me
 

Users who are viewing this thread

Back
Top Bottom