8.6. Using VBA in Forms and Reports
Much of the power and flexibility of applications built using Access comes from the VBA code that you can use behind your forms and reports. Although code-less forms and reports can provide a lot of good functionality, they really shine when VBA coding techniques are added.
Access Wizards provide a first look at VBA code behind forms and reports. However, Wizard-built code is just scratching the surface. Here are some guidelines and techniques that will help you build extra functionality into your Access applications.
8.6.1. All About Me
Me is a very special word in Access VBA. It is a reference to the form or report that your code is running in. For example, if you have some code behind the form frmBusiness, anytime you use Me in that code, you get a reference to the form object of frmBusiness.
This is a beautiful thing because there are many times that you need a reference to your own form or report, such as when you need to make it visible. You could refer to it directly, like this:
Forms!frmBusiness.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 enables 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 ...
Get Access™ 2007 VBA Programmer's Reference now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.