Discussion Locked

Me. ???

0 helpful
7 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I see this (Me.) in various VBA Access code samples and I have searched for it's meaning/purpose but have never found it. Could someone please tell me what it means and any resources you might know.

Feel free to email me at hayco@door.net

Thanks
Tom

7 replies

by yatst

in vb "Me" stands for whatever control the code is meant for.

Ex: if you are in a function for a form named frmOrder and a text box named txtName. In your code instead of writing frmOrder.txtName.(whatever) each time you want to refer to it, you type Me.(and the rest of your code).

by haycoconsulting

Appreciate the quick response.

Where/how do you assign this (as it appears to me to be) alias for the form/control?

Maybe I'm just slow but I would appreciate a slightly more detailed answer/short example.

Thanks,
Tom

by mbarker734

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

Hope this helps,

Mark

This discussion is closed to new replies.