View Full Version : "ME" Code


jblackman
04-04-2001, 06:36 AM
Can someone explain the difference between:
Me![Combo13]
and
Me.Combo13

Is there a difference in the way this is coded?

Rich@ITTC
04-04-2001, 07:20 AM
Hi J Blackman

My understanding is that the ! (bang) is used before items the User/Developer has named and the . (dot/period) is used before MS Access names.

So

Me.Requery

would be Ok as "Requery" is a term named by Access.

Me!Requery

wouldn't be OK.

Likewise

Me!cboNamedMyMe

would give the value of the combo box that you had named, but the following would not work:

Me.cboNamedByMe

Some references can use both:

Forms!frmMyForm!txtMyTextBox.Locked = Yes

"Locked" has a dot before it as it is an Access property/command/etc. The other parts have a bang as they are user/developer named.

HTH

Rich Gorvin

AlanS
04-04-2001, 11:06 AM
Here's the official explanation from the Access 97 online help:

Use the ! and . (dot) operators in expressions

You use the ! and .(dot) operators in an identifier to indicate the type of item that immediately follows.
The ! operator indicates that what follows is a user-defined item (an element of a collection). For example, use the ! operator to refer to an open form, an open report, or a control on an open form or report.

Identifier Refers to
Forms![Orders] The open Orders form
Reports![Invoice] The open Invoice report
Forms![Orders]![OrderID] The OrderID control on the open Orders form
The . (dot) operator usually indicates that what follows is an item defined by Microsoft Access. For example, use the . (dot) operator to refer to a property of a form, report, or control.

Note You can also use the . (dot) operator to refer to a field value in an SQL statement, a Visual Basic for Applications method, or a collection. For example, the identifier Forms![Orders].Controls refers to the Controls collection of the Orders form. However, because the Controls collection is the default collection for forms and reports, it's usually not necessary to refer to it explicitly.

Pat Hartman
04-04-2001, 05:35 PM
Forms and Reports actually append the columns of their recordsource to their properties collection so either:
Me![Combo13]
and
Me.Combo13
will properly reference Combo13. The difference is that the bang (!) uses late binding and the dot (.) uses early binding. The effect in this case is that the reference using the dot will be resolved by the compiler but the reference using the bang will not be resolved until run time. Therefore if you mistype the column name, Me.Combo13a will produce an error immediately but Me!Combo13a will not produce an error until the code is actually executed.

There is another advantage to using the dot form of reference and that is that Access will produce helpful dropdowns as you type. So, typing Me. will produce a list of available properties, including all the columns of the recordsource and the controls on the form/report and then Me.Combo13. will produce a list of the available properties for the column.

To avoid confusion, it is best to make sure that each control name is different from the name of the column to which it is bound. If you use the wizard to create a form or report, Access will automatically name the control with the same name as the column it is bound to. This is NOT very helpful since it makes ONLY the control available with the dot reference. For example, if you have a column named Cust and a control also named Cust, you will see only one instance of Cust in the dropdown and it will be refering to the control which is not exactly obvious. However, if you rename the control to txtCust, you will then see both Cust and txtCust and now Cust will refer to the column from the recordsource and txtCust will refer to the name of the control.

One more relevant piece of information. If you make any changes to the recordsource after the form or report is built, you will have to force Access to manually "refresh" it's property collection in order to "see" the new columns using the dot reference. The method for doing this is to delete the recordsource, save the form/report, then re-add the same reference (either table or query) back into the recordsource property and save the form/report again.

jblackman
04-04-2001, 06:45 PM
All very interesting responses.... thank you all very much for the detail.... This site never ceases to amaze me. Have a great week!