dots and bangs- Why bang then?

cogent1

Registered User.
Local time
Today, 04:19
Joined
May 20, 2002
Messages
315
I have recently read in a posting by Pat Hartmann that the dot(.) operator is preferable to the bang(!) in referring to fields in code because it creates early binding and is generally a Jolly Good Thing!
I accept this statement as coming from a competent authority,but it begs the question as to why the bang is there in the first place and why so many books on Access programming don't mention the interchangeability of the two operators?

Should we ban the bang?
 
I beleive the rule-of-thumb is:

dot (.) is for properties
bang (!) is for data fields (such as the recordset in your form.

This is the main reason it is always strongly suggested that your "Controls" have different names then your Recordset fields.

The bang is also a good way to include a field that does not have a Control on your form/report in a calculation.
 
For me, the difference is mainly this:

As a matter of consistency, I use bang as a separator between table and field even sometimes when I really don't need to, particularly if I am also going to use dot on the table to pick up on the table's properties in VBA code.

When I'm in a query grid, it doesn't matter because you don't normally access properties from a query grid. Now, in queries based on SQL that cannot appear in a query grid, I don't think you can get at table properties but then, I've never actually tried that.

In forms and reports it normally doesn't matter because from text boxes, combo boxes, and the like, you don't access properties as recordsources or controlsources. But in the VBA underneath the code, it makes a big difference for readability.

In VBA, there are cases where you MUST use bang because dot doesn't work. And there are cases where you must use dot because bang doesn't work. Usually having to do with discovery of or enumeration of collections. So of course, there I do what I need to do to make it work.

I usually am forgiving of Access when it gives me dot-bang grief, though. After all, it IS a Gates product. So I pity it rather than censure it.
 
There really is some consistancy. You just have to stumble across it.

Dot is always used when referencing VBA properties and methods

Bang is always (except two cases) used when referencing user defined objects. The two exceptions are the field collections of forms and reports. In these two cases, Bang and Dot are interchangeable but the Dot has the early binding I wrote about in the other post. The reason that Dot works in these cases is because Access treats the fields of the bound recordsource for a form/report as properties and adds them to the form/report collection.

There are idiosyncrasies that you need to be aware of when using the Dot in these cases. Since the recordsource fields are added to the collection at the time that the recordsource is specified, if you happen to change the query, there is nothing that will prompt the form/report to automatically refresh its properties collection to "see" the new fields. The fields list will show them but if you were to try to use them in code, you would get compile errors. You can force Access to refresh the properties collection by deleting the recordsourse/saving the form/report and then re-adding the queryname to the recordsource. This will now make the new fields available for reference via Dot in VBA.

Someone asked about Dot and Bang recently and I went looking for that old post of mine but couldn't find it. If anyone can post a link to it, I would appreciate it.
 
Thanks for these clarifications. Since posting my question, I have read in a programming tome that the bang operator is also a JGT, the Jet engine likes it better, it's faster etc. I wonder what's true and ultimately, for the databases I write, whether a microsecond here or there makes any great difference. But it's interesting, so thanks for the input.
 

Users who are viewing this thread

Back
Top Bottom