Saturday, May 31, 2008

Dot vs. Bang: Put to Rest

The issue of whether two use a DOT(.) or BANG(!) when referring to a form field or control in Access VBA viz:
  • Form1.Control1
  • Form1!Control1

has been an issue of contention ever since Access 95.

Now Access MVP Michael Kaplan in a post on the Access Team Blog has provided a definitive guide:

  • The dot gives you early binding and is resolved at compile time, the bang is resolved at runtime.
  • In the case of Forms, both controls and fields in the underlying query can be referenced via a dot since they are all in the type library for the form.
  • Also in the case of Forms, if you change the underlying query at runtime - dot references to the old query's fields will fail at runtime since update of the Form's type library cannot happen at runtime.
  • Because the dot is early bound, IntelliSense happens by default with the dot, not with the bang.
  • The dot (since it is early bound) is faster than the bang, but no one runs enough code that uses these items enough for the performance difference to actually matter.

I have been a long-time convert to the DOT based on the sheer convenience of the IntelliSense default being the DOT.