Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Looking for good FAQ or Doc on !, . and [] 1

Status
Not open for further replies.

bjdobs

Programmer
Mar 11, 2002
261
CA
Is there a Faq or clear description of Rules on when to use;
!
.
[]
 
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)

[tt]txtTst, txtTst.value, me.txtTst, me.txtTst.value, me!txtTst, me!txtTst.value, me.controls!txtTst, me.controls!txtTst.value, me("txtTst"), me("txtTst").value, me.controls("txtTst"), me.controls("txtTst").value, etc...[/tt]

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

Here's the link used by those claiming dots (.) is THE RIGHT WAY;-)
Cleaner Coding: Bang vs. Dot

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

Roy-Vidar
 
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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top