13.8. The Me Property

The Me keyword is an implicitly declared variable that is automatically available to every procedure in a class module. When a class can have more than one instance, Me provides a way to refer to the specific instance of the class where the code is executing. Using Me is particularly useful for passing information about the currently executing instance of a class to a procedure in another module.

The Me keyword contains an object reference to the current class instance, and can be used by code written in forms, reports, and user-defined classes. It returns faster than a fully qualified object reference, and is useful when you have several instances of a class. For example, either of the following code fragments can be executed from the Employees form to refer to the value of the LastName text box on that form.

strLastName = Forms!Employees.LastName
strLastName = Me!LastName

You can also use Me to pass information about the current class instance to a procedure in another module or class. The code in the following sections demonstrates a class that subclasses a form, and binds to the subclass instance from the form.

13.8.1. Subclassing the Form

This class defines a portion of the subclass named clsFormSubclassed. Because the subclass stores an instance of an Access Form object, all properties of the form are available in the subclass.

Private WithEvents mfrmMyForm As Form Public Property Get FormObject() As Form Set FormObject = mfrmMyForm End Property Public ...

Get Access™ 2007 VBA Programmer's Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.