Applies To Form, Report.
Description
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.See Also ActiveForm property, ActiveReport property, Form, Report properties, Parent property, Screen object.
Example The following example shows how to change the caption of a Customers form to a value supplied by the user. The ChangeCaption subroutine passes the Me property (representing the Form object) to specify the active form. Because the ChangeCaption procedure changes the caption of the active form (not a specific form), it can be called from other procedures in an application.ChangeCaption Me, InputBox("Enter new caption " _
& "for form")
Sub ChangeCaption(frmCurrentForm As _
Form, strCaption As String)
' Change caption.
If TypeName(frmCurrentForm.Caption) = "Null" Then
frmCurrentForm.Caption = strCaption
Exit Sub
End If
If UCase(strCaption) _
<> UCase(frmCurrentForm.Caption) Then
frmCurrentForm.Caption = strCaption
End If
End Sub