I think the only clear rule you'll find, is that you must use [] when you have spaces or special charachters in names of your objects, and that when referencing form controls in queries (well, and in controlsources when referencing in main/sub form setups), you need the bang (!) notation.
When referring to properties and methods, dot must be used, for instance the recordsetclone property of a form:
[tt]me.recordsetclone[/tt]
The usual way to describe this can be for instance: "In general, you follow the bang with the name of something you created: a form, report or control. The bang also indicates that the item to follow is an element of a collection. You'll usually follow the dot with a property, collection, or method name." (Getz et all, adh 2000)
Else there are lot of threads here, info on the net on the multitude of preferences. Let's take referring to a text control on a form. Access in most versions will allow something like this (txtTst)
It's mostly about preferences. Using the dot (.), is preferred by many vs bangs (!), cause it's a bit more convenient when coding (the intellisence dropdown).
Hovewer, two things to consider
* sometimes, very, very rare, though, you might get into trouble using the me.txtTst notation (dot (.)), cause Access get's confused about what it refers to.
* what kin of reference is Microsoft using in their documentation (help files...)
All that said, my preference is either me("txtTst").value or me.controls("txtTst").value...
Both bang and brackets can be used to pick out a member of a collection.
However, one expects a literal value and the other a variable.
For example, I just experimented in Excel - Worksheets("Sheet1") and Worksheets!Sheet1 were equivalent.
However, Worksheets(xxx) (no quotes) will look for a vba variable called xxx and then try to substitute the value of xxx in order to look up the sheet.
So if you know that a specific object (whether a control on a form or a sheet in an Excel workbook) will not change its name you can use the bang notation and avoid the brackets and quotes.
If you want to work through a collection use a variable inside the brackets.
The dot is often tolerated in place of the bang but the original intention was that the dot should indicate a property or method of an object.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.