Me Property

Applies To

Form, Report.

Description

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

Setting

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

Remarks

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 creating generic procedures that operate on the current form, the preferred method is to pass the form to the procedure using the Me property rather than the ActiveForm property.

See Also

ActiveForm Property; ActiveReport Property; Form, Report Properties; Parent Property; Screen Object.

Example

The following example shows how to change the caption of the Customers form to the current company name whenever a new record is displayed. The form’s Current event procedure calls the ChangeCaption subroutine and passes it the Me property to specify the active form. The ChangeCaption procedure changes the caption of the form. Because the ChangeCaption procedure changes the caption of the active form (and not a specific form), it can be called from other procedures in an application.


Sub Form_Current()
    ChangeCaption Me        ' Pass current form name as argument.Sub
ChangeCaption(frmCurrentForm As Form)
    ' Move focus to Customer Name text box.     frmCurrentForm![CompanyName].SetFocus
    ' Change caption.
    frmCurrentForm.Caption = frmCurrentForm![CompanyName].TextSub