Microsoft Office 2000/Visual Basic Programmer's Guide   

Creating Property Procedures

As mentioned previously, public module-level variables in a class module function as properties of an object. However, they're not very sophisticated. If you need to run code in order to set or return a property's value, or you want to make a property read-only, you can create a Property procedure. There are three types of Property procedures: Property Get, Property Let, and Property Set procedures. The Property Get procedure returns the current value of a property, whereas the Property Let procedure sets the value. The Property Set procedure assigns an object to an object property.

To create a read-write property, you need to include a pair of Property procedures in the class module. Both procedures must have the same name. If the property stores and returns a scalar value, such as a numeric, text, or date value, you use a Property Let procedure to set the value and a Property Get procedure to retrieve it. If the property stores and returns a reference to an object, you use the Property Set procedure to store the reference and the Property Get procedure to return it.

You can also create read-only, write-only, and write-once properties. The following table outlines which property procedures you need for each type.

Type of property Procedures needed
Read-write, scalar Property Let, Property Get
Read-write, object Property Set, Property Get
Read-only, scalar Property Get
Read-only, object Property Get
Write-only, scalar Property Let
Write-once, scalar Property Let, including code to determine whether property has been set previously, Property Get
Write-once, object Property Set, including code to determine whether object property has been set previously, Property Get