Me

See Also3N7W9D

Me is a reserved word in Visual Basic that behaves like an implicitly declared variable.  It is automatically available to every procedure (Sub or Function) in a form.  In an environment where you can have more than one instance of a form, Me provides a way to refer to the specific instance of the form where the code is executing.  Using Me is particularly useful when you want to pass information about the current instance of a form to a procedure in another module.  For example, suppose you have the following procedure in a module:

   Sub ChangeFormColor(FormName As Form)

      FormName.BackColor = RGB(Rnd * 256, Rnd * 256, Rnd * 256)

   End Sub

 

You can call the procedure and pass the current instance of the form as an argument using the following statement in one of the procedures in your form:

   ChangeFormColor Me

 

In most cases the form referred to by Me is the same as the form referred to by Screen.ActiveForm.  However, it is possible for the two to be different.  Screen.ActiveForm always refers to the form that has the focus while Me always refers to the form where code is executing.  For example, a Timer event can occur in a form that does not have the focus.  When that happens, Screen.ActiveForm refers to the form with focus, while Me refers to the form where the Timer event occurred.


See Also

ActiveForm PropertyGCUI9X