Class modules tend to represent a real-world object (although this is not
always the case) ... you can also pass class objects around to various
function and procedures (something you can't do with Std modules) ... etc
etc. With a Class Module, you can have more than one object instantiated at
a time. For example, let's say you have a clsTire object with the following
Let/Get properties:
RimSize
TreadWidth
SideWallHeight
BrandName
With this method:
***************************************
Function FindTire(TireID As Long)
Dim rst As ADODB.Recordset
Set rst = New.ADODB.Recordset
rst.Open "SELECT * FROM tblTires WHERE lngTireID=" & TireID,
currentproject.connection
If Not rst.EOF and Not rst.BOF Then
RimSize = rst("strRimSize")
SideWallHeight = rst("strSideWallHeight")
TreadWidth = rst("strTreadWidth")
BrandName = rst("strBrandName")
End If
End Function
***************************************
If you wanted to compare two different tires sizes, you would instance two
separate tire objects:
Dim clsTire1 as clsTire
Dim clsTire2 As clsTire
Set clsTire1 = New clsTire
Set clsTire2 = New clsTire
clsTire1.FindTire 3
clsTire2.FindTire 5
At this point, clsTire1 contains info regarding a tire with the ID of 3, and
clsTire2 contains info regarding a tire with the ID of 5 ... something you
really can't do with Standard modules (without a LOT of Public variables,
which are not a great idea)
Class modules also allow you to include logic that represent other
characteristics of the object. For example, let's say you wanted to know
what types of rims you have in stock that will fit a particular tire ...
you could include a Method of your class that would report this info to you
merely by making a call to the class:
Me.lstListOfRims.ValueList = clsTire1.GetAvailableRims
This is just a very, very basic view of Class modules. For more information,
Google on "VB OOP", "class modules" etc etc