O'Reilly logo

Access™ 2007 VBA Programmer's Reference by Armen Stein, Geoffrey Griffith, Rob Cooper, Teresa Hennig

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required