All About Me

Me is a very special word in Access VBA. It is a reference to the form or report that your code running in. For example, if you have some code behind the form frmBusiness, then anytime you use Me in that code, you get a reference to the form object of frmB-usiness.

This is a beautiful thing because there are many times that you need a reference to your own form or report, like when you need to make it visible. You could refer to it directly, like this:

FormsifrmBusiness.Visible = True

Or, you can use the Me reference instead:

Me.Visible = True

Obviously, the Me reference is much shorter and easier to type. But there is a far greater reason to use Me. It allows you to move code from one form or report to another, where it automatically adapts to its new home.

The Me object is a full reference to a form object. Not only can you refer to it, but you can also pass it to other functions as a parameter. All you have to do is define a function with a parameter with a Form data type, and you can pass the Me reference to it. This technique is used in the Better Record Finder technique shown in Appendix I, "Tips and Tricks."

It's good that you can pass Me as a parameter, because it doesn't work outside a form or report's code. Remember, Me refers to the form or report that the Me references lives in, not the form or report that's currently active. So Me will not work in a stand-alone module.

0 0

Post a comment