Chapter 28: Object-Oriented Programming with VBA
991
Definitions of property procedures for the same property are
inconsistent, or property procedure has an optional parameter, a
ParamArray, or an invalid Set final parameter.
FIGURE 28.9
The property variable data type must coincide with the property’s data type.
Class Module
Private m_ProductID As Long
Public Property Let ProductID (Value As Long)
Public Property Get ProductID() As Long
A
m_Product ID= Value
End Property
End Product
C
D
ProductID = m_ProductID E
B
Caution
Although you can use an incorrectly typed private variable for your property procedures, you’ll encounter
side-effect bugs if the variable doesn’t match the data type used for the property procedures.
Modifying the Product Class
Earlier in this chapter, I built a simple product class representing a Northwind product. The initial
class is included in the Access .accdb file accompanying this chapter as the clsProduct1 class
module. In this section, I extend the initial class (as the clsProduct2 class module) by making
its properties more intelligent and useful.
Specifically, this section extends the property procedures within the Product class module, and
adds methods to the module. I also expand the basic application by adding a few other classes
needed to support the Northwind Traders application.
The example application accompanying this chapter includes a form named Products_OOP,
which is based on the Products form included with Northwind Traders (see Figure 28.10). This
form utilizes the majority of OOP techniques described in this chapter and can serve as a model for
your OOP endeavors.