Microsoft Access 2010 Bible

(Rick Simeone) #1

Chapter 28: Object-Oriented Programming with VBA


975


FIGURE 28.1

You’ll use the name you provide for the class module as the object’s class name (clsProduct in this
case).


Creating simple product properties
The easiest way to establish the properties of a class, and the technique you’ll use in your first class
example, is to simply declare each of the properties as a public variable in the clsProduct1 class
module. Adding a public variable to a class module creates a new property for the class. The vari-
able’s public scope makes it accessible to other routines in the database. In the “Using Property
Procedures” section, later in this chapter, you’ll see an alternate way to create properties for your
class modules.

Public ProductID As Long
Public Name As String
Public Supplier As String
Public UnitPrice As Currency
Public UnitsInStock As Integer
Public ReorderLevel As Integer
Public Discontinued As Boolean

Figure 28.2 shows the class module after you’ve added the public variables.

FIGURE 28.2

Public variables in a class module become properties.

Free download pdf