title: VBA Classes - How to have a class hold additional classes
body: <p>I have a challenge that I am trying to solve using classes.</p>
  
  <p>I am logging transactions into a class.</p>
  
  <p>Each transaction has the following:</p>
  
  <ul>
  <li>Name</li>
  <li>Date</li>
  <li>Time</li>
  <li>Description</li>
  </ul>
  
  <p>However each transaction can also have many business related contacts with the following properties</p>
  
  <ul>
  <li>Business Contact Name</li>
  <li>Business Area</li>
  <li>Percentage of Bill</li>
  </ul>
  
  <p>Are there any examples of how this would be done. </p>
  
  <p>I have tried adding a second class for the business contact and then building a collection inside the transaction class, all with no joy.</p>
  
  <p>I have also tried making the business contact details a collection within the transaction class also with no joy.</p>
  
  <p>Below is what I have so far, but i may have gone down a blind alley and it may not be worth trying to rescue the code</p>
  
  <p>Any help much appreciated.</p>
  
  <p>Thanks
  JP</p>
  
  <hr>
  
  <h2>Test sub - trying to write the data in and get it back out</h2>
  
  <pre><code>Sub test()
  
      Dim x As Integer
      Dim xx As Integer
  
      'code to populate some objects
      Dim clocklist As Collection
      Dim clock As classClocks
      Dim businesscontactlist As Collection
      Dim businesscontact As classBusinessContact
  
      Set businesscontactlist = New Collection
      Set clocklist = New Collection
  
      For x = 1 To 3
          Set clock = New classClocks
          clock.LawyerName = "lawyer " &amp; Str(x)
          For xx = 1 To 3
              businesscontact.Name = "Business Contact " &amp; Str(xx)
              businesscontactlist.Add businesscontact
  
          Next xx
          clock.BusinessContactAdd businesscontactlist '----- errors here
          clocklist.Add clock
      Next x
  
      Set businesscontactlist = Nothing
  
      'write the data backout again
      For Each clock In clocklist
          Debug.Print clock.LawyerName
          Set businesscontactlist = clock.BusinessContacts
          For Each businesscontact In businesscontactlist
              Debug.Print businesscontact.Name
          Next
  
      Next
  
  End Sub
  </code></pre>
  
  <hr>
  
  <h2>Clock Class - this is the transaction class</h2>
  
  <pre><code>Private pLawyerName As String
  Private pBusinessContactList As Collection
  
  Public Property Get LawyerName() As String
      LawyerName = pLawyerName
  End Property
  
  Public Property Let LawyerName(ByVal sLawyerName As String)
      pLawyerName = sLawyerName
  End Property
  
  Public Property Get BusinessContacts() As Collection
      Set BusinessContacts = pBusinessContactList
  End Property
  
  Public Property Set BusinessContactAdd(ByRef strName() As Collection)
      Set pBusinessContactList = New Collection
      Dim businesscontact As classBusinessContact
      Set businesscontact = New classBusinessContact
  
      For Each businesscontact In strName
          businesscontact.Name = strName.Item()
          pBusinessContactList.Add businesscontact
      Next
  End Property
  </code></pre>
  
  <hr>
  
  <h2>Business contact Class - For the moment it only has one property</h2>
  
  <pre><code>Private pBusinessContactName As String
  
  Public Property Get Name() As String
      Name = pBusinessContactName
  End Property
  
  Public Property Let Name(ByVal sName As String)
      pBusinessContactName = sName
  End Property
  </code></pre>