using modulename in code (1 Viewer)

Rene vK

Member
Local time
Today, 18:14
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.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 00:14
Joined
May 7, 2009
Messages
19,246
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.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 12:14
Joined
May 21, 2018
Messages
8,555
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.
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 17:14
Joined
Sep 12, 2006
Messages
15,662
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?
 

Rene vK

Member
Local time
Today, 18:14
Joined
Mar 3, 2013
Messages
123
Ok, point taken. From this day on I will use the modulename in my coding!
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 12:14
Joined
May 21, 2018
Messages
8,555
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
 

isladogs

MVP / VIP
Local time
Today, 17:14
Joined
Jan 14, 2017
Messages
18,247
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.
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 17:14
Joined
Sep 12, 2006
Messages
15,662
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.
 

Isaac

Lifelong Learner
Local time
Today, 09:14
Joined
Mar 14, 2017
Messages
8,784
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
 

Rene vK

Member
Local time
Today, 18:14
Joined
Mar 3, 2013
Messages
123
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.
 

Isaac

Lifelong Learner
Local time
Today, 09:14
Joined
Mar 14, 2017
Messages
8,784
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:

JMongi

Active member
Local time
Today, 12:14
Joined
Jan 6, 2021
Messages
802
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!
 

Isaac

Lifelong Learner
Local time
Today, 09:14
Joined
Mar 14, 2017
Messages
8,784
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.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 11:14
Joined
Feb 28, 2001
Messages
27,239
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.
 

Isaac

Lifelong Learner
Local time
Today, 09:14
Joined
Mar 14, 2017
Messages
8,784
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.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 12:14
Joined
Feb 19, 2002
Messages
43,372
I use Me. for the intellisense as well as for the way it ties the name to the form where the code is running. I also give my control names prefixes to distinguish them from the bound field name so Me.txtChangeDT refers to the CONTROL and it's properties (including .value) and Me.ChangeDT refers to the bound field. If you change the value of Me.ChangeDT directly, the value change does not appear on the form in Me.txtChangeDT but the change does get saved. This can be confusing. The prefixing is a hangover from earlier versions of Access where there were problems referencing control properties if you didn't do that. Once I train myself to do something, I don't deviate or change unless I find a better alternative. Consistency is your friend when you are programming. As a consultant, I tend to work on multiple applications for multiple clients so I always have hundreds of object and field names I'm working with at any time so knowing that i always do things the same way saves a lot of brain strain.

I don't know what would happen if you Dim'd a field name ChangeDT and referenced it, would you be referring to the variable or to the bound field? Things like this can cause serious programming errors so Me. is also a way of disambiguating the reference to avoid any conflict.

I don't include the module name when I use procedures or functions. As someone already mentioned, you can always find where something is defined by right-clicking on it in the code.

I always use Call ProcedureName. Probably a hang over from my COBOL years where "Call" was required. I seem to remember you can also Call FunctionName if you are not using/expecting a return value from the function but can't check to verify right now.
 

CJ_London

Super Moderator
Staff member
Local time
Today, 17:14
Joined
Feb 19, 2013
Messages
16,636
I will use module name for form modules - but not for standard modules - chances are I wouldn't remember the name anyway ;)
 

apr pillai

AWF VIP
Local time
Today, 21:44
Joined
Jan 20, 2005
Messages
735
Me. works within the loaded Form/Report Module.

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

Form_Form1.myFunction()
 

Users who are viewing this thread

Top Bottom