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.
AccessWizards 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 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:
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 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 ...
Get Access 2003 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.