Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Programming style question - should I always use me. ??

Status
Not open for further replies.

SBendBuckeye

Programmer
May 22, 2002
2,166
US
I'm just getting started in serious Access development. Should I always use the me. operator for clarity? Are there performance issues one way or the other? Are there other issues I haven't recognized or don't know enough to ask?

Thanks for the help. I want to start from the getgo doing things in the best manner possible.
 
If you are a beginning programmer it is probably best to use all of the identifier designations so that you don't get confused in your code. Me! contains the object reference to the current form or report and is faster than a fully qualified object reference. So you will never be confused when debugging your code as to what object you are referring to. You can also use the Me reference in a class module to retrieve a reference to the current class module object.

I always try to refer to my database objects by a prefix:
Tables - tblTableName
Queries - qryQueryName
Forms - frmFormName
SubForms - frmSFFormName
Module - basModuleName
Variables - vVariableName
Global Variables - vgVariableName

This naming convention helps our simple minds to categorize the names and keep them straight within out code. I do not believe that there is any overhead other than a little database size due to the extra characters necessary to store the name that should be an issue.

There are programming techniques that you can use later than will help with the coding issues so that you do not have to use the me![objectName]or me!objectname conventions that shorten your keycoding process. (i.e. With statement etc.)

With MyLabel
.Height = 2000
.Width = 2000
.Caption = "This is MyLabel"
End With

as opposed to

me![MyLabel].Height = 2000
me![MyLabel]..Width = 2000
me![MyLabel]..Caption = "This is MyLabel"

But, in the beginning it is recommended that you overidentify the object to make it clear to yourself so that you the programmer understand fully the object that you are manipulating.

I hope I made this a little clearer to you.

Bob Scriver
 
Although I'm normally a stickler for using styles for clarity, and would recommend using Me. consistently, I have to confess I'm very careless about it in fact. I tend to always use it for form methods and properties, but often or even usually omit it with control and field properties. I think that's probably because expressions containing control names are often so long that they overflow the line width (which I control for printing purposes), and using Me. increases the frequency with which I have to insert a line break.

I did a quick benchmark to test accessing the Top property of a command button, with and without Me. Over 327,680 iterations, taking 26 seconds, there was no difference within a resolution of 1 second. So I'd say there was no performance impact when you use Me. (This was in Access 97, but I doubt Access 2000 would be different. Access XP might be different, though.)

With regard to other issues, only one comes to mind. If you have a local variable (within a Function or Sub procedure) that happens to have the same name as a Form property or a control, then you can't refer to the property or control without using Me. References without Me. will refer to the variable. Of course, it's poor form to declare a variable with such a name in the first place, but occasionally it happens by accident. That's one good reason to use type prefixes on all variables. Rick Sprague
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top