Me. or Me !

  • Thread starter Thread starter Richard
  • Start date Start date
R

Richard

What is the difference between these two statements?

For L = 1 To Me!TotalParcels
For L = 1 To Me.TotalParcels

Thanks
Richard
 
The practical difference is the Access checks that Me.TotalParcels is valid
at compile time (when you type it), but Me!TotalParcels is not checked until
runtime. Consequently, I prefer to use Me.TotalParcels, so if I misspell a
name I discover my error I discover my error straight away, not later when
some poor user is told I stuffed up.

For a more detailed explanation, see Andy Baron's article:
Cleaner Coding: Bang vs Dot
at:
http://my.advisor.com/articles.nsf/aid/05352

There's one other case that's worth mentioning. Access matches these
expressions to either (a) a control (text box) on the form, or (b) a field
in the form's RecordSource (even if there's no text box with that name.) In
some cases, it stuffs up with (b), so don't every use the dot for (b.) I'd
suggest you don't use (b) at all, i.e. always put a text box on the form
(even if you hide it), as that avoids other problems also associated with
this AccessField type.
 
excellent thank you!

Allen Browne said:
The practical difference is the Access checks that Me.TotalParcels is valid
at compile time (when you type it), but Me!TotalParcels is not checked until
runtime. Consequently, I prefer to use Me.TotalParcels, so if I misspell a
name I discover my error I discover my error straight away, not later when
some poor user is told I stuffed up.

For a more detailed explanation, see Andy Baron's article:
Cleaner Coding: Bang vs Dot
at:
http://my.advisor.com/articles.nsf/aid/05352

There's one other case that's worth mentioning. Access matches these
expressions to either (a) a control (text box) on the form, or (b) a field
in the form's RecordSource (even if there's no text box with that name.) In
some cases, it stuffs up with (b), so don't every use the dot for (b.) I'd
suggest you don't use (b) at all, i.e. always put a text box on the form
(even if you hide it), as that avoids other problems also associated with
this AccessField type.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.



.
 
The practical difference is the Access checks that Me.TotalParcels
is valid at compile time (when you type it), but Me!TotalParcels
is not checked until runtime. Consequently, I prefer to use
Me.TotalParcels, so if I misspell a name I discover my error I
discover my error straight away, not later when some poor user is
told I stuffed up.

The actual difference is that with the . you're depending on VBA
creating a hidden property wrapper around your controls and fields
and maintaining it correctly. You can't control it, you can't undo
it, you can't fix it if it breaks (and some small percentage of
times it does break).

I completely avoid using the . operator for control/field references
on forms/reports -- I exclusively use the ! operator. I live without
compile-time checking and thus avoid the remote possibility of
corruption in the hidden property wrappers.

Basically, my philosophy is to never depend on VBA to properly do
something for you that you have no control over.
 
Back
Top