Me. or Me!

R

Ripper

Simple question. I see in different places people using Me.Field=Yes or
me!field=Yes

What is the difference between ! and . ? Just a question on coding I guess.
 
T

Tony Toews [MVP]

Ripper said:
Simple question. I see in different places people using Me.Field=Yes or
me!field=Yes

What is the difference between ! and . ? Just a question on coding I guess.

We've had these lengthy discussions in the past favouring one way or
the other. IIRC some have stated that Access would crash or cause
other wierdnesses if the dot was used. So I've been using the ! for
maybe a decade now.

However a client has been using dot for a few years now. Now we're
doing our development in A2003 but I have had no problems with the
dot. And it's more convenient in that you get form control
intellisense to help avoid typos.

I look forward to other comments on this issue.

Tony
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/
 
A

Allen Browne

Andy Baron has a fairly clear explanation of what the differencd is:
Cleaner Coding: Bang vs. Dot
at:
http://my.advisor.com/articles.nsf/aid/05352

Like Tony, I use the dot whereever I can, because the dot allows VBA to:
a) auto-complete the variable names (quicker, more accurate),
b) catch errors at compile time.
Anything that helps make the application is bug-free has to be worth it.

I do use the bang for referring to fields, not controls:
a) You must use the bang for fields of a Recordset. (Dot won't compile.)
b) The dot does not work reliably when referring to AccessFields.

An AccessField is the (hidden) type when a name does not resolve to a
control, but is there as a field in the RecordSource of form. For example,
if the form's source query has a field named CustomerID, but there is no
text box named CustomerID, then Me.CustomerID or Me!CustomerID is of type
AccessField. There seem to be inconsistencies in the way Access handles this
data type, so under certain conditions, Me.CustomerID will fail. You then
solve it either by adding a text box named CustomerID (hidden if you wish),
or by using Me!CustomerID. So, having been bitten a few times, I always use
the bang rather than the dot for AccessFields.
 
T

Tony Toews [MVP]

Allen Browne said:
Andy Baron has a fairly clear explanation of what the differencd is:
Cleaner Coding: Bang vs. Dot
at:
http://my.advisor.com/articles.nsf/aid/05352

Like Tony, I use the dot whereever I can, because the dot allows VBA to:
a) auto-complete the variable names (quicker, more accurate),
b) catch errors at compile time.

I'd forgotten about b but yes. Especially if you rename a control on
a form or whatever.

Tony
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/
 
Top