[AccessD] How explicit do you need to be?

Kenneth Ismert kismert at gmail.com
Mon May 3 13:55:53 CDT 2010


Hi all,

Comments inline:

Darryl Collins:
> ...Personally I have always been very precise with references etc as it
> seems to improve performance and reliability.  However, does it really
> matter that much?
> ...
> x = txtMyTextBox  VS  x = me.txtMyTextBox.value
> ...
>

It doesn't matter at all when you are referencing controls within a form
module.

But, other languages enforce the use of "this" to refer to the current
object instance, so using "me" seems like good practice. As you mentioned,
me also leverages Intellisense.

Jim Dettman:
> ...When you do this:
> With me
>  .txtFarm.Visible = False
> End with
>  VBA knows for sure that it's really:
>  me.txtFarm.Visible = False
>

VBA knows for sure in with or without the me. Just plain txtFarm.Visible is
early-bound, too. Try misspelling a plain txtFarm reference, and see what
VBA does.


> ... I also do things like:
>  Dim db as DAO.Database
>  Rather then:
>  Dim db as Database
> ...Well first, I don't know if or when I might add ADO to a project, so
> it's
> good to have them on.


That is a valid reason to specify the type library.


> Second it's faster because VBA knows exactly which
> lib reference I mean.
>

Not at runtime. Both are early-bound references, and both run equally fast.
It might be a tiny bit faster to compile, but that is negligible. The real
reason to specify type is your first reason.

jwcolby:
> ... I always use ! to reference controls and . to reference properties.
>

That's fine, but ! references are always late-bound. So, if you have a
control called txtExample, and refer to it as me!txtWrongName, your project
will compile just fine, and you'll only get an error at runtime when VBA
tries to resolve the reference. That's why I prefer . for control
references, and only use ! for recordset fields.

-Ken



More information about the AccessD mailing list