me!?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

could someone please explain to me the role of the 'me!' function in visual
basic code? what exactly does it refer to?

thanks

jake
 
From the Help file (under Me property):

You can use the Me property in Visual Basic to refer to a form, report, (or
to the form or report associated with a subform or subreport), or class
module where Visual Basic code is currently running.

Setting

The Me property is available only by using Visual Basic and is read-only in
all views.

Remarks

The Me property contains an object reference to the current form or report
and is faster than a fully qualified object reference. For example, the
following two code fragments refer to the value of the LastName control for
the current record on the Employees form:

strLastName = Forms!Employees.LastName

strLastName = Me!LastName

In most cases, the form or report referred to by the Me property is the same
form or report referred to by the ActiveForm or ActiveReport properties of
the Screen object. However, these properties refer to the form or report
with the focus, whereas the Me property always refers to the form or report
in which code is running. For example, a Timer event can occur in a form
that doesn't have the focus. When that happens, the code Screen.ActiveForm
refers to the form with the focus, and the Me property refers to the form in
which the Timer event occurred. Therefore, when you are creating generic
procedures that operate on the current form, the preferred method is to pass
the form to the procedure by using the Me property rather than the
ActiveForm property.

You can use the Me keyword in class modules to refer to the current instance
of that class. Just as you use Me in form or report class modules to
retrieve a reference to the current form or report, you use Me in a class
module to retrieve a reference to the current class module object.
 
Me refers to the class module of the form, with all its properties and
methods.

You can think of it as being the form, i.e.:
Me.[Surname]
refers to the control named Surname on this form.

It use is optional but, it helps when you are typing because it fires the
Intellisense so Access completes the names of things for you, resulting in
fewer spelling errors. Then it helps again at compile time, because Access
catches the name if it is incorrect. Then it helps again at runtime, because
there are fewer things that the reference could refer to, and so less chance
of the code being misinterpreted.
 
Back
Top