Dot or Bang?

Published 30 May 08 05:39 PM

Here's a question that comes up from time to time. The other day, someone internally asked about the difference between using a dot "." vs. a bang "!" for control references in a form in VBA. In other words, given a form - Form1, with a control - Control1, what are the differences between:

Form1.Control1    ' Control reference using a dot

- and -

Form1!Control1    ' Control reference using a bang

Michael Kaplan was kind enough to respond with the following:

  • 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.

Thanks Michael for responding!

Comments

No Comments
New Comments to this post are disabled

About robcooper

Rob Cooper is a Test Lead at Microsoft working on Microsoft Access. He started at Microsoft in 1998 working in Access product support in Charlotte, NC and then moved to Redmond to join the test team in 2001. For Access 2007, Rob worked on the new Grouping Pane for Reports, and security features such as Database Encryption and Disabled Mode. He is also a co-author on Expert Access 2007 Programming and Access 2007 VBA Programmer's Reference, both published by Wrox. Rob also spends time on www.utteraccess.com reading and answering questions.
Page view tracker