O'Reilly logo

Beginning Access™ 2007 VBA by Denise Gosnell

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

4.2. Create Custom Properties for Existing Objects

Now that you have worked with existing objects and created your own objects, you will see a few ways to extend existing objects, giving them additional properties, methods, or events. Start by looking at how to create custom properties for existing objects.

4.2.1. Using Existing Tag Property

One way to create a custom property for an existing object is to use the Tag property. The Tag property is only used when you write code to set the value and then use that value later for some specified purpose. For example, you might use the Tag property to hold a value and then retrieve that value at a later time.

4.2.2. Using Public Variables

As described earlier, when you create properties for your custom objects, you can also create properties for existing objects, using public variables. To do so, just add the public variable declaration to the class module of the existing object, such as an existing class for a form. Again, this is not the recommended way to create properties. As discussed previously, I do not recommend this approach for three primary reasons. First, you cannot manipulate the value because the property is set; second, you cannot create read-only and write-only properties; third, you cannot easily validate what is assigned to public variables. A better way to create properties, discussed next, does not have these drawbacks.

4.2.3. Using Property Let, Property Get, and Property Set Routines

You can use the Property ...

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