O'Reilly logo

Access 2003 VBA Programmer's Reference by Armen Stein, Graham Seach, Teresa Hennig, Patricia Cardoza

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required