correct syntax: bangs or dots?

jguscs

Registered User.
Local time
Today, 15:51
Joined
Jun 23, 2003
Messages
148
what is the correct syntax?


Me.Control.Property
or
Me!Control.Property


Forms!MyForm.Control.Property
or
Forms!MyForm!Control.Property
 
A "!" is a way of separating an object from a collection. The "." is used to separate an object from a collection, property, or method.

I think all those forms that you listed will work (though I haven't tried them).

The way you wrote it, "Control" is the name of a control and thus is a member of the controls collection that belongs to the "Me" form object.

The full syntax of this expression: Me!txtBox.Name is this Me.Controls("txtBox").Properties("Name"). Since the controls collection is the default for the Me form object, you can abbreviate it to Me("txtBox"). Then you can replace the ("") format with "!" since txtBox is an object in the controls collection, so you have Me!txtBox or Me.txtBox.

It's best to use the full notation when possible, since behind the scenes, Access is actually expanding all your notation for you, but I wouldn't get nuts over it.
 
Dot and Bang are only interchangable when using Me to refer to a control on a form or report. When using the Forms! collection, you need to use the Bang. So 1,2, and 4 are correct but 3 is not.

Using the Dot syntax has a great advantage because it enables early binding so that intellisense is available while you're typing and you can tell that you have mistyped a name when you don't see a properties list.
 
Pat, I was able to use this syntax:
MsgBox Forms!frmTest.txtTest.Name and it worked. It produced the same result as:
MsgBox Forms!frmTest!txtTest.Name

In this case, I believe it was because the txtTest field is a member of the controls collection for the form's controls. Therefore the "." notation and the "!" notation are equivalent.

I almost never use the "!" notation because it doesn't work with Intellisense. The only time I've found that I had to use it was in queries where I had to refer to a field in a form.
 

Users who are viewing this thread

Back
Top Bottom