3.3. Ways to Refer to Objects

You should also know the various ways to refer to an object. Here are some examples:

Forms.frmTestObjects
Forms!frmTestObjects
Forms("frmTestObjects")
Forms(0)

Using the period (Forms.frmTestObjects) is my personal preference for most situations because you can see the list of available properties, methods, events, and constants as you type. You already saw this used with objects earlier in this chapter.

You can also refer to objects using the Me keyword as a shortcut. Me refers to the current object. So if you use Me in a form module, it refers to the form. Here is an example:

Me.txtDateOfBirth

An equivalent, but longer, version of the same statement is:

Forms.frmTestObjects.txtDateOfBirth

Only use the Me keyword when you want to refer to the existing object (not to a totally different object).

Get Beginning Access™ 2007 VBA 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.