I want to create the following structure:
I have created the following code:
Userform with a commandbutton (used to activate the code)
Option Explicit
Public myCollection As Collection
Private Sub CommandButton1_Click()
Dim subItem As SubClass
Dim baseItem As BaseClass
Set baseItem = New BaseClass
Set subItem = New SubClass
subItem.itemName = "Something"
baseItem.addSubItem (subItem) <---- ERROR ON THIS ROW!
myCollection.Add (baseItem)
End Sub
Private Sub UserForm_Initialize()
Set myCollection = New Collection
End Sub
BaseClass
Option Explicit
Private subClassCollection As Collection
Public Sub addSubItem(subItem As SubClass)
Call subClassCollection.Add(subItem, Key:=subItem.itemName)
End Sub
Private Sub Class_Initialize()
Set subClassCollection = New Collection
End Sub
SubClass
Option Explicit
Private sItemName As String
Property Get itemName() As String
itemName = sItemName
End Property
Property Let itemName(name As String)
sItemName = name
End Property
When I run this code I get the following error "Object doesn't support this property or method" on the highlighted row in the Userform.
I thought this example would be simple enough.. what am I missing?