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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Me. or Me! 1

Status
Not open for further replies.

CharlesCook

Programmer
May 13, 2002
424
US
Hi all,

Somewhere I remember seeing somthing on using ! vs . and I can't find it now.

I allways use this syntax:
Me.controlname.Value
and it works fine.

But I see this syntax used all the time:
Me!controlname.Value

Can someone enlighten me on this AND/OR point me to some doc on this.

Thanks

CharlesCook.com
ADP - PeopleSoft - SAP
ReportSmith - Crystal Reports - SQR - Query - Access
Reporting - Interfaces - Data Mining
 
OK - for documentation, see for instance the help files, or other information from Microsoft. You will find mainly the bang (!) notation, but sometimes also the parenthesis/quote notation, but not the dot notation, i e something like this

[tt]me!txtSomeControl
me!txtSomeControl.value
me("txtSomeControl")
me("txtSomeControl").value[/tt]

of course, with or without specifying the default property, and for the latter one, with or without specifying the default collection, as in for instance

[tt]me.controls("txtSomeControl").value[/tt]

But the dot notation, then? Here's one article supporting that Cleaner Coding: Bang vs. Dot (is it the only one?)

For another explanation, check out the section "Bang (!) versus Dot (.) versus Quotes ("")" in Chapter 6: ActiveX Data Objects from ADH by Ken Getz, Paul Litwin, Mike Gilbert.

My take on the issue, is that
1 - there are situations where one of the methods must be used over others, the simple sample is discussing form control references in queries and controlsources, where the bang notation must be used (but there are also some situations where the dot notation will not work), so they have separete usages, and are different method of referencing which is needed for different purposes
2 - what to use in the rest of the situations, is, in my humble opinion, a matter of preference. A lot of developers seems to prefere the dot notation, because it gives the intiellisence when typing Me. in a form or reports class module (in stead of typing Me! then hit ctrl+space) for forms where the recordsource and controlsource is set prior to programming.

You might want to have a read at some of the lengty discussions on this topic. A search through your favourite web search engine on the terms Access Bang Vs Dot, should produce some hit. Here's also one of numerous threads on the topic at CDMA

Roy-Vidar
 
Thanks so much for your reply. Here is a star....

I will look @ the docs you referenced.

CharlesCook.com
ADP - PeopleSoft - SAP
ReportSmith - Crystal Reports - SQR - Query - Access
Reporting - Interfaces - Data Mining
 
When you read the reference that Roy suggested here is an important quote (ADH by Ken Getz, Paul Litwin, Mike Gilbert):

It turns out that, behind the scenes, the former style of dot-and-bang reference is translated to the latter style of parentheses-and-quotes reference when you execute such a statement. This means that, although using the bang operator will save you a bit of typing, you'll pay for it in a speed penalty.

So I always try to use the parentheses where possible.
 
So

Forms.("formname").control

would be better then

Form_formname.control

CharlesCook.com
ADP - PeopleSoft - SAP
ReportSmith - Crystal Reports - SQR - Query - Access
Reporting - Interfaces - Data Mining
 
Actually it is Collection Name(object index). So it is
Forms("formname") not Forms.("formname"). The index can be the actual index number or the name. So something like
Forms(3).controls(2)
may be the same as
Forms("frmXYZ").controls("txtBxCDE")
The reason that a lot of these different looking methods work has to do with VB use of default properties, collections, and methods. These loose standards make things a lot easier to code, but add a lot of confusion.
 
I agree with everything else that was said. It helps to have developed a few objects. Once you have built your own objects, you will start to think of the dot notation as denoting properties or methods that you built.

Think of the dot notation as an object address and read a dot as "belongs to ".

You might google subclassing. Subclassing is a powerful technique that allows you to modify the normal behaviour of the controls and forms in your application, and add custom properties and methods, which you can then call.

With Me.cmdComments
.SetFocus 'method
.Caption = "&New Comment" 'property
.customproperty
End With

Hope this helps.

Alan
 
My way of remembering it is

If you defined the name then put a bang (!) in front of it
If Microsoft defined the name then put a dot (.) in front of it

EXCEPT in JET SQL strings where it is dots all the way.


Eg Forms!myformName!subfrmName.Form!txtboxName.Visible

Form and Visible are 'system' words ( Properties or Methods etc. ) so they get a dot prefix.

myformName, subfrmName and txtboxName are names I have defined for objects to they get a bang prefix.




G LS
spsinkNOJUNK@yahoo.co.uk
Remove the NOJUNK to use.
 
Little Smudge,
Not a really true statement, especially if you do any work with class modules. The bang notation deals with default collections of an object. When you have Form!txtBoxName the reasons that this works is that vb says go to the default collection which is "controls" and get the object named txtBoxName. The bang works with default collections. The same works with recordsets because the "Fields" collection is the default collection.
If I define a name in a class object (property or method) then I have to call it with a dot. For example define a public variable on a form's module and call it strCallingForm. Now from another form call your form and you can set the public variable

forms("frmName").strCallingForm = me.form.name

 
I just knew it was too simplistic a rule.

I fully accept what you're saying MajP

:-(

G LS
spsinkNOJUNK@yahoo.co.uk
Remove the NOJUNK to use.
 
Thank ALL of you for a VERY enlightening dialog !!!!

CharlesCook.com
ADP - PeopleSoft - SAP
ReportSmith - Crystal Reports - SQR - Query - Access
Reporting - Interfaces - Data Mining
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top