Part IV: Professional Database Development
1002
FIGURE 28.13
The InvalidSupplierID event appears in the Object Browser.
You’ll notice a couple other events — InsufficientStockAvailable and ProductSold —
in the Product class module. I’ve added the other events in exactly the same manner as the
InvalidSupplierID event. An event declaration is all that’s required to add an event to a
class’s interface. The class module never even has to trigger an event shown in the Object Browser.
Raising events
An event that is never invoked by a class module’s code isn’t much use to anybody. Events are typ-
ically triggered (or raised) whenever circumstances indicate that the consumer should be notified.
Raising an event requires a single line of code:
RaiseEvent <EventName>(<Arguments>)
I discuss event arguments in the “Passing data through events” section, later in this chapter. In the
meantime, take a look at raising the InvalidSupplierID event from the SupplierName
Property Get:
Public Property Get SupplierName() As String
Dim varTemp As Variant
If m_SupplierID <= 0 Then
RaiseEvent InvalidSupplierID()
Exit Property
End If
varTemp = DLookup(“CompanyName”, “Suppliers”, _
“SupplierID = “ & m_SupplierID)
If Not IsNull(varTemp) Then
SupplierName = CStr(varTemp)
Else