What is Me.[object]?

Is this long ago post from SJ not really valid

SJ McAbney08-19-2003, 10:53 AM
Using the dot syntax (early binding) asks VBA to work out the object’s nuances at compile time meaning that the application knows exactly what is expected of objects as it has, basically, predetermined their characteristics beforehand which can dramatically increase the speed of your application.

Using the exclamation mark syntax (late binding) allows your application to compile but the application determines the objects at runtime, and the time taken to determine can increase performance time as you are essentially asking VBA to use an object but it must first decide what sort of object it is.

i.e.

Me.txtMyTextbox

This line allows VBA to know we are referring to the form and it knows the object txtMyTextbox is a textbox and thusly allows you access to its methods and properties.

Me!txtMyTextbox

This line is asking VBA to work out what sort of object txtMyTextbox and then evaluate it.

For optimising your database then you should really use early binding. The only caveat with using early binding is that it requires the reference libraries to compile. If you don’t have the references to these libraries then the application’s compilation will fail. The only time, to be honest, that you should use late binding is when a component does not support early binding.

Brian
 
I'm not so sure how true that is, as the ! and . identifiers usually differentiate between a object collection and a specific object within that collection. I also don't agree with early binding in some cases as it forces objects that may or may not be used. For example, this is early binding:

Dim rsMyRecordset As New ADODB.Recordset

Space will be made for that recordset, regardless of whether or not it ever gets used. The late binding equivalent is this:

Dim rsMyRecordset As ADODB.Recordset
.
.
Set rsMyRecordset = New ADODB.Recordset

This doesn't reserve memory for the recordset unless it's actually used. While there is a performance difference, I have found that it's negligible at best. The performance difference was more pronounced when we weren't working with 2GHz+ processors and 1GB+ of RAM, but with technology the way it is now, the difference between early and late binding usually comes down to 1000 milliseconds or less, depending on the situation.
 
I'll probably continue to use Me. when I can
1 Out of habit
2 I can't make spelling /typo mistakes if I'm selecting from a list :D

Brian
 
I'm not so sure how true that is, as the ! and . identifiers usually differentiate between a object collection and a specific object within that collection. .

Pat Hartman put it this way

To clarify, the ! is used when referencing user defined objects and the . is used when referencing internal methods and properties. The place where there is overlap is in the fields collections of forms and reports. In this case, and in this case only, you may use the . and ! interchangably because your recordsource fields and the forms controls are all part of the fields collection.

Brian
 
I can't belive that there are so many contrary and confused opinions on this topic.

Me. is a way of referencing a method or property of the ACTIVE object. There is no confusion for example with controls on other forms that might have the same name. The scope of the reference is the ACTIVE object and since only one object may be active at a time, Me. can never refer to anything outside the current object. Me. is never used in standard modules because modules are not an object with methods and properties.

The general distinction is that the bang "!" is used to qualify user defined objects and the dot "." is used to qualify Access defined objects. The exception to this rule is the fields collection of a form. Even though the controls are user defined, Access includes them in the form's collection so that when you reference them with Me. you get the benefit of intellisense.

Intellisense is a wonderful thing and for that reason alone, I ALWAYS use Me. when I can since it prevents me from making typos and also minimizes the amount of typing I have to do.

Using Me. also gives you a visual reference in code that you are referencing a control rather than a variable.
 
I was thinking it'd be good to have Pat around for this one a here she is :)
 
My Heroine has spoken, when I worked I used to get in early so that I could read all of Pat's posts from the previous night, its my only ACCESS education.

Brian
 
Pat, it's not that there's confusion about the Me. keyword referring to the active object. That's true. Instead, it's confusion (at least a little bit) about seeing Me.<control> and not being sure what "Me." is referring to in its specific context. If you've got a Main Menu, and then open a form from that Main Menu that contains two subforms, the Me. identifier can be a little confusing for the uninitiated, or if it's an application you aren't familiar with.

Like you intimated, I will use Me. to get the control's name right (no typos), but I'll then remove the "Me." part of it. There's really nothing wrong with using Me. or with not using it. It's essentially personal preference. I don't use it often, but that's just me. I know plenty that do use it.

The idea here is to get people to understand what Me. does in the first place. It's just a shortcut. And thanks for backing up my "bang" collection "dot" object explanation. :)
 
Last edited:
Pat, it's not there's confusion about the Me. keyword referring to the active object. That's true. Instead, it's confusion (at least a little bit) about seeing Me.<control> and not being sure what "Me." is referring to in its specific context. If you've got a Main Menu, and then open a form from that Main Menu that contains two subforms, the Me. identifier can be a little confusing for the uninitiated, or if it's an application you aren't familiar with.

Like you intimated, I will use Me. to get the control's name right (no typos), but I'll then remove the "Me." part of it. There's really nothing wrong with using Me. or with not using it. It's essentially personal preference. I don't use it often, but that's just me. I know plenty that do use it.

The idea here is to get people to understand what Me. does in the first place. It's just a shortcut. And thanks for backing up my "bang" collection "dot" object explanation. :)

Maybe the confusion started when I put my unqualified 2cents worth in :)
 
Thank you for your kind words. I can't tell you how much I have learned from this forum. Now if only someone would add to my reputation:)

Moniker, leave the Me. Access has to work less to compile the code because the Me. tells Access where it is defined. Without that, it first scans its own list of commands and functions, then it scans the global variables, then it scans the local variables, then it scans the fields collection of the form or report - I am just guessing at the actual search sequence but I wanted you to understand what is involved in "compiling" a program. The compiler first needs to determine where/if a string is defined to know what it is and how to interpret it. Anything you can do to reduce that work will speed up the execution time. Granted, you need a lot of code to see significant improvement but if you get in the habit of using the most efficient method, you are less likely to have to go back into working code to modify it to obtain speed increases.
 
Thank you for your kind words. I can't tell you how much I have learned from this forum. Now if only someone would add to my reputation:)

QUOTE]

I allready did. Not that it needs adding to for us old posters.
I'm a real creep considering the views I expressed about the reputation thingy in site suggestions.:)

Brian
 
Note that Pat and I both have two green dot things next to our names. HA! ;)

On a more serious note, I've never heard of Me. actually speeding things up (negligible or not), if only because Access needs to figure out what "Me." refers to. I've always taken it as a shortcut and a way to get a list of controls in IntelliSense. In a quick test, I didn't visually notice a difference on a form with around fifty controls. Explicit declarations will increase speed, yes, but Me. means different things in different contexts.

Regardless, I think we've exhausted to purpose of the Me. keyword (the original question posted here) and we're now just picking preferences. I could be wrong on this of course, but I think we're 2-3 posts away from "My Xbox 360 kicks your PS3's ass!" and other fanboy nonsense.

Thanks for the tips on how Me. gets compiled though. :)
 
Yes, it's a joke. Yeesh! I even included the smiley to indicate that.

[joke]Maybe I'll use joke tags next time so there's no confusion.[/joke]
 

Users who are viewing this thread

Back
Top Bottom