using modulename in code (1 Viewer)

Rene vK

Active member
Local time
Today, 16:35
Joined
Mar 3, 2013
Messages
123
@Pat Hartman is fiercely ;) teaching us to use 'Me.' when adressing a control. I started doing that, most of the time.

My question now: is it also common use to refer a module when calling a procedure or function from somewhere else? I sometimes use it, mostly not.
 
if you have Similar public sub/functions Names in different modules, it is advise
to use modulename.sub/func name so you don't get any errors.
 
Both are rarely needed but make life a lot easier with intellisense to get your code correct. Type Me. and up come the proper names to select. Same with the module name. I have lots of modules and instead of swapping over to find the name I can simply type the module and the methods show up to select.
 
Both are rarely needed but make life a lot easier with intellisense to get your code correct. Type Me. and up come the proper names to select. Same with the module name. I have lots of modules and instead of swapping over to find the name I can simply type the module and the methods show up to select.
That's great. I just never knew you could do that.

Can you find a function easily when you don't know which module it's in?
 
Ok, point taken. From this day on I will use the modulename in my coding!
 
If you have a very large app possibly with modules you inherited, you may have private methods with the same name in different modules. Rare, but I have seen it. If for some reason if you need to use them you can by the module name

call moduleOne.HelloWorld
cal moduleTwo.HelloWorld
 
FWIW I always use prefixes such as Me. & Parent. to refer to form controls in order to make use of intellisense

However I NEVER use the module name or Call when referring to Public Functions as I see no advantage in using either
If I need to know the location of the function, I right click the function and click definition

Each to their own approach.
 
FWIW I always use prefixes such as Me. & Parent. to refer to form controls in order to make use of intellisense

However I NEVER use the module name or Call when referring to Public Functions as I see no advantage in using either
If I need to know the location of the function, I right click the function and click definition

Each to their own approach.
"definition" (and other stuff) too. No idea you could do that, although you can do Shift-F2 to do a similar (the same?) thing.
 
I don't use the module name, nor Call either, although I suppose sometimes the module name might be nifty if you forget names or whatever
 
I don't use the module name, nor Call either, although I suppose sometimes the module name might be nifty if you forget names or whatever
It could be a good use when you have to handover an application to a client. I did some work for a client, where the contractor left the plant, and the databases would stay alive. In my world contracors tend to hire people for jobs like building a database. It is a big thing going through code in a situation like that.
 
I should clarify, I DO use the module name when referring to forms (unless i'm coding in the form's class module, then of course I use Me.) it gives you intellisense and that's priceless to me.

What an absolutely cruddy language VBA is, that Microsoft doesn't keep it alive and add features to it. We should have 10x the intellisense we have. you only have to work in visual studio for an hour in your whole lifetime to realize how we suffer in vba. /rant
 
Last edited:
This is so true. And I'm completely unskilled in that arena but tried to teach myself some Visual C++ back in the day and the intellisense actually helped me understand the lessons!
 
all i know is vb.net in visual studio, but the intellisense is off the charts (almost overwhelming at times, actually), and vba they just let it crust over and fester in obsolescence.
 
I suspect that MS's treatment of VBA is somewhat akin to Big Pharma's treatment of drugs for which the patent has expired (thus allowing the introduction of generics). Can't make so much money anymore, so relegate it to the woodpile.
 
I suppose that must be true, since they probably know what they're doing money-wise. It just puzzles me because Office is still huge, 365 is big, and they must know that everyone beyond tinkerers enjoys the automate-able aspect. But I suppose they see serious VBA developers as a very, very tiny subset of the world.
 
I will use module name for form modules - but not for standard modules - chances are I wouldn't remember the name anyway ;)
 
Me. works within the loaded Form/Report Module.

How do we Call/Reference a Public Function from another Form/Report Module?

Form_Form1.myFunction()
 
You cannot reference a function in a different class module unless the form/report is actually open.
You are late to the game again, and really should read the whole thread because we beat this topic to death. As posted this would work, although as I pointed out a bad idea.
Code:
Form_Form1.myFunction()

That line of code opens an instance of the form hidden, and it goes out of scope once the procedure exits. So yes you can do it.

This demo would highlight
Code:
Private Sub Command1_Click()
  MsgBox "There are " & Forms.Count & " open"
  Form_Form1.HelloWorld
  MsgBox "There are " & Forms.Count & " Open"
End Sub

This procedure executed from form2 will run the method in form1 because this line instantiates an instance and runs the method.
Form_Form1.HelloWorld

Bottom line this can be done, but IMO should never be done unless you full understand. You are opening an instance of a form with all the overhead.
 

Users who are viewing this thread

Back
Top Bottom