'Class Name: CDispensaryItems Option Explicit Private mDispensaryItems As Collection Public Enum diError diItemCodeError = vbObjectError + 512 + 1 End Enum Private Sub Class_Initialize() 'Create the collection object Set mDispensaryItems = New Collection End Sub Private Sub Class_Terminate() 'Release the collection reference Set mDispensaryItems = Nothing End Sub Private Function NextDispensaryItemCode() As String 'Assign the next DispensaryItemCode Static intDispensaryItemCode As Integer intDispensaryItemCode = intDispensaryItemCode + 1 NextDispensaryItemCode = Trim(Str(intDispensaryItemCode)) 'Convert to string End Function Public Sub Add(ByVal intFrameStyle As Integer, ByVal intFrameSize As Integer, _ ByVal intQuantity As Integer) 'Add a new member to the collection 'Object variable to hold the new object Dim NewDispensaryItem As New CDispensaryItem With NewDispensaryItem 'Set up the properties for the new object 'Call the function to assign the next key .DispensaryItemCode = NextDispensaryItemCode .FrameStyle = intFrameStyle .FrameSize = intFrameSize .Quantity = intQuantity mDispensaryItems.Add NewDispensaryItem, .DispensaryItemCode End With End Sub Public Sub Remove(ByVal strKey As String) 'Remove a member from the collection On Error GoTo HandleError mDispensaryItems.Remove strKey Remove_Exit: Exit Sub HandleError: Err.Raise diItemCodeError, "CDispensaryItems", "Invalid dispensary item key" End Sub Public Function Item(ByVal strKey As String) As CDispensaryItem 'Return one member from the collection On Error GoTo HandleError Set Item = mDispensaryItems.Item(strKey) Item_Exit: Exit Function HandleError: Err.Raise diItemCodeError, "CDispensaryItems", "Invalid dispensary item key" End Function Public Property Get Count() As Long 'Return the number of members in the collection Count = mDispensaryItems.Count End Property Public Function NewEnum() 'Allow for the For Each...Next enumeration Set NewEnum = mDispensaryItems.[_NewEnum] End Function