Strictly speaking Me is a reference to the current instance of the class in
whose module the code is running, but think of it in terms of a reference to
the current form (or report) as mostly that's how it will be used.
To better understand its real meaning, you could for instance have more than
one instance of the same form open simultaneously, each at a different record
say. Now if, in one instance, you were to refer to a control on the form by
a full reference such as Forms!MyForm!MyControl there is no way of knowing
from this which instance of the form, and therefore which record, is referred
to. If Me.MyControl is used, however, then this refers to the control on
that instance of the form in whose module the code is running.
In most cases Me can in fact be omitted, but its best not to do so. Your
example would probably work just as well as:
HourlySalary = CDbl(txtHourlySalary)
One thing to note is that you can only use Me in VBA, don't use it in an
expression used as the ControlSource of a computed control for instance.
Normally in a case like that you'd just omit it, e.g. for an unbound
GrossPrice control you might have:
=[NetPrice] * (1+[TaxRate])
Though you can, but normally wouldn't, use the Form property in place of Me
in a case like this:
=Form.[NetPrice] * (1+Form.[TaxRate])
The Form property, as you'd expect returns a reference to the current form.
There are some situations where its useful, but mostly you'd omit it.
Ken Sheridan
Stafford, England
iamrdbrown said:
I am just beginning to learn VBA & have run across the following syntax in
some of the lessons I am following online:
'Retrieve the hourly salary
HourlySalary = CDbl(Me.txtHourlySalary)
My question (that isn't covered in my lesson) is this: Does the Me._____
identify that the information being looked for is on the current form/page?
Or does it mean something else entirely?
Thanks in advance for any help in clarifying this one.
R Brown