Microsoft Access 2010 Bible

(Rick Simeone) #1

Part IV: Professional Database Development


976


Access treats each public variable in a class module as a property of the objects created from the
class. Because you declare the public variables in a class module, Access uses the variables as prop-
erties of the class’s objects without further work on your part. Figure 28.3 shows how IntelliSense
displays the properties in the Auto List Members drop-down list in a module using an object cre-
ated from the class.

FIGURE 28.3

IntelliSense shows you the properties and methods created for the new object class.


Because the object’s properties are variables in the class module, the names you assign to these
items must conform to VBA’s variable naming requirements:

l Property names must be 64 or fewer characters.

l (^) Property names can contain only alphanumeric characters and the underscore character.
l Property names must begin with an alphabetic character and can never begin with the
underscore character or a number.
Tip
The names you provide for an object’s properties and methods should be descriptive and easy to recognize.
Creating methods
The clsProduct1 class includes two methods: Sell and Discount. These methods, like all
object methods, define actions supported by the objects created from the class. Each method is
nothing more than a public procedure in the object’s class module.
l (^) Sell: The following code example shows the procedure implementing the Sell method.
Because all procedures in a class module are public by default, the Public keyword is
optional and you add it to the Sell method to clarify the status of the procedure.

Free download pdf