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

"." vs "!" 6

Status
Not open for further replies.

BigTeeJay

Technical User
Jun 13, 2001
106
US
Greetings,
Along the lines of faq181-447 (which I am not able to understand, the poor guys post appears to have been mangled in the process)... I am trying to figure out when it is appropriate to use "." vs "!".

For example if referencing a control on the current form, you could do Me.ControlName, or it seems you can do Me!ControlName, or sometimes you use Forms.formname, and other times Forms!Form_Formname, or is it Forms!Formname!?!?!

Does anyone know of a document (or could share a rules of thumb) that would help clarify this?

Regards,
Tj
 
Hallo,

I think it's ! for fields and controls, and . for everything else, although in a lot of cases you can use either, which doesn't help understanding.

Me!frmSubform.Form!cboControl

Because frmSubform is a control of Me, Form is a property of the subform control and cboControl is a control of the subform.

Easy, huh?

- Frink
 
The exclamation mark (also called bang operator) stands for "string parameter to the default property or method".

That needs some explanation. Many collections have a default method or property routine. If you look in the object browser, right click, and check "show hidden members", you'll see them. A standard collection, for instance, has an
Code:
item
method, which is both default and hidden. Personally, I don't like it that it is hidden, but that's the way it is.

Now if you pass the default method a string, you can abbreviate it with a bang operator. If the variable frm is a form, you can write:

Code:
frm!cmdOk
as shorthand for
Code:
frm.Controls.Item("cmdOk")

(the Controls collection is the default property of Form and the Item property is the default property of Controls.)

With Forms, there is something extra:
Each control you add becomes a public property of the form itself. So with controls on a form you can use both the bang and the dot operator.

Hope this explains a bit.

Best regards
 
From Access help:
Code:
Use the ! and . (dot) operators in expressions

You use the ! and .(dot) operators in an identifier to indicate the type of item that immediately follows.
The ! operator indicates that what follows is a user-defined item (an element of a collection). For example, use the ! operator to refer to an open form, an open report, or a control on an open form or report.

Identifier	              Refers to
Forms![Orders]	          The open Orders form
Reports![Invoice]	       The open Invoice report
Forms![Orders]![OrderID]    The OrderID control on the open Orders form

The . (dot) operator usually indicates that what follows is an item defined by Microsoft Access. For example, use the . (dot) operator to refer to a property of a form, report, or control.
 
Although there is some confusion over the idea that the BANG and the DOT are interchangeable, here's the way I define it to my students:

Use the ! before anything YOU have made, and the . before anything Microsoft has made.

Forms!MyForm.RecordSource

I made MYFORM, but M/S came up with the RECORDSOURCE concept. It's really as simple as that.

Jim








Me? Ambivalent? Well, yes and no....
Another free Access forum:
More Access stuff at
 
Hello all,
There seems to be a lot of misunderstanding as to the use of the bang (!) operator :-(. As I stated in the crosspost of this thread thread705-488511, the ! operator is used to access items in a collection.

Please look at the following:
Or to be exact:
This should clear up any confusion. If not check out:
Robert
•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•
Professional, affordable, Access database solutions and assistance °•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°•°
 
WildHare,
I like your explanation best. It's easy to remember when you've been working 20 hours straight and you're pulling your hair out. That's exactly what I look for in a rule of thumb.

This was a concept that I didn't understand very well until today. Thank you to all of you who posted explanations (in either thread).
 
Thanks for the replies... in an effort to consolidate the knowledge/resource for others... please follow up in this thread: thread705-488511

Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top