Microsoft Access 2010 Bible

(Rick Simeone) #1

Part IV: Professional Database Development


978


Eventually, with enough work and attention to detail, you can refine the product class to the point
where it would support all the features and requirements of a real product sold by Northwind
Traders. Other classes could model other data in the Northwind database such as customers, employ-
ees, and orders. In the “Recognizing the Benefits of Object-Oriented Programming” section, later in
this chapter, you’ll see some of the advantages of using class modules in your Access applications.

Using the product object
After you’ve assembled the class module from properties and methods, you can create new objects
from the class. Figure 28.4 shows frmProductUnbound, a form included in Chapter28.
accdb, the database accompanying this chapter. The text boxes along the left side of this form dis-
play the object’s properties. The buttons to the right side of this form invoke the object’s methods.

FIGURE 28.4

frmProductUnbound creates an object from clsProduct1 and provides an interface to its properties
and methods.


Creating a new product object requires you to use the New keyword. This statement is one way to
create a new instance of a product object from the clsProduct1 class module:

Private Product As New clsProduct1

Alternatively, you can first declare the Product object, and then instantiate as separate state-
ments. For example, place this statement in the module’s Declarations section to establish the
clsProduct1 object:

Private Product As clsProduct1

The object instantiates in the form’s Load event procedure:

Set Product = New clsProduct1
Free download pdf