Difference between "." and "!" ? (1 Viewer)

Z34Lee

Registered User.
Local time
Today, 08:21
Joined
Dec 8, 2006
Messages
22
Not sure how to search for this one, so I'll just ask. What's the difference in using a dot or an exclamation point in the fashion of:

Me.controlname
or
Me!controlname

I see different versions of this particularly in referencing controls or objects outside the current module.
 

boblarson

Smeghead
Local time
Today, 05:21
Joined
Jan 12, 2001
Messages
32,059
This is a quote from a post from Pat Hartman:
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.
The post is located here:
http://www.access-programmers.co.uk/forums/showthread.php?t=28739&highlight=bang
 

Z34Lee

Registered User.
Local time
Today, 08:21
Joined
Dec 8, 2006
Messages
22
Thanks for the reply. It looks like a somewhat confusing topic, but from what I gathered, in my applications it shouldn't make any difference.
 

Epax

Registered User.
Local time
Today, 07:21
Joined
Jan 10, 2007
Messages
14
Bob,
Wow thanks. Just so i understand. If I have a unbound combobox on in the header of a form, what will the best way of accessing the text property of the combobox?
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 08:21
Joined
Feb 19, 2002
Messages
43,478
It would be rare that you would reference the .text property of a control. In Access, the property you want is most likely the .value property which is the default property. The .text property is ONLY addressable when the control has the focus. You would reference the control as:

Me.SomeControlName
or
Me.SomeControlName.Value

Thanks for the reply. It looks like a somewhat confusing topic, but from what I gathered, in my applications it shouldn't make any difference.
It does make a difference. To summarize, you reference "things" you created and named with the bang (!) and "things" that are integral to Access with the dot (.).
 

Epax

Registered User.
Local time
Today, 07:21
Joined
Jan 10, 2007
Messages
14
Here is what I am running into. I have a form that is unbound until the user sets the criteria for the SQL that I build from code. The user does this by means of combobox, checkboxes, etc... each of which is unbound. Now, everything works until I set the record source. Once the record source is set the OnChange event of the ComboBox no longer sees the ComboBox as a valid control of the form.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 08:21
Joined
Feb 19, 2002
Messages
43,478
You probably shouldn't be using the OnChange event. It fires each time a character is typed into the control. You will have more success using the AfterUpdate event of the combo.
 

Epax

Registered User.
Local time
Today, 07:21
Joined
Jan 10, 2007
Messages
14
All works as long as you use a sub form to show the data and keep the main form's record source blank.
 

Users who are viewing this thread

Top Bottom