In a nutshell - I don't know - there have been volumes written in the
newsgroups on this subject! If you'll do a search in google groups for "Bang
vs. Dot" you'll find a
slew of threads on the topic. Here's my abridged explanation (and
preferance).
Bang (!) is used to denote a member of a collection. Controls on a form are
members of the form's controls collection and thus we can reference a
control on a form by using the bang notation me!MyControl to refer to
MyControl on the form in which the code is executing.
Dot is used to refer to a property or method of a class (the form is a
class). Me.visible would refer to the Visible property of the form.
Where it gets confusing is that by default, Access creates a property for
every control on a form. This has the caveat of allowing the developer to
use the dot notation as another way of referencing a control on a form. So
you can refer to a control using me.MyControl
Underneath the covers, both types of control references are converted to the
fully qualified control reference via the form's controls collection -
So:
me!MyControl
me.MyControl
both get converted to
me.controls("MyControl")
What's the best notation to use? You'll have to decide for yourself but I'd
suggest you do the search on google and read what I and others have already
written. I prefer the Dot style notation primarily for two reasons - first
it makes my job easier because I can type in 'me.' and then select my
control name from the property list. Second and perhaps more importantly,
the compiler will catch invalid property references
me.CtlNotHere will not compile
me!CtlNotHere will compile but will create a runtime error
AFAIK the only place where you can not avoid using the bang is in a query
parameter that references a control on a form.
A couple of other notes (thanks to Dirk Goldgar for pointing these out to me
a while back . . . )
If you're referring to a subform, this won't work (the abridged reference to
a subform control that was introduced in A2000 I believe:
Forms!MainForm.Subform1.ControlOnSubform
You have to write it as either
Forms!MainForm.Subform1!ControlOnSubform
or
Forms!MainForm.Subform1.Form.ControlOnSubform
I always use the last syntax for references to controls on subforms anyway
(which is why I always forget to mention it).
For further reading on the topic (after your own Google search) Here's a
link to a good article on this subject by MVP Andy Baron:
"Cleaner Coding: Bang vs. Dot "
http://www.advisor.com/Articles.nsf/aid/BAROA06
The Access Developer's Handbook (2000 and probably 2002) (Litwin, Getz,
Gilbert) also has a good discussion on this issue.
--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this newsgroup.
Eric said:
can somebody put in a nutshell the difference between the
bang (!) and the dot (.) ? Thanks.
e.g. [forms]![thing] or forms.thing, etc...
Eric