title: VBA - How to add a collection to a collection of collections
body: <p>I am trying to create code to represent a form document using VBA in Word 2007. I have created classes to represent Section, QuestionSet and Question.</p>
  
  <p>So I have 15 Sections. I have created a function to create each 'Section' Object add it to the 'Sections' Collection then destroy the object, the result being that the objects remain persistent in the collection (or something).</p>
  
  <p>Is it possible to use the same method to add collections to collections or would I have to define each collection explictly?</p>
  
  <p>Code in Module:</p>
  
  <pre><code>Public Sections As Collection
  
  Function DefineSection(ByVal SectionName As String)
  
      Set Section = New clsSection
      Section.myName = SectionName
      Sections.Add Section, SectionName
  
  End Function
  
  
  Function DefineQuestionSet(ByVal SectionName As String, ByVal Name As String, ByVal NoOfQuestions As Integer, ByVal IsMutuallyExclusive As Boolean, Optional ByVal DependentOnSection As String)
  
      Dim Qsets As Collection
  
      Set Qsets = New Collection
      Set QuestionSet = New clsQuestionSet
  
      QuestionSet.Name = Name
      QuestionSet.NoOfQuestions = NoOfQuestions
      QuestionSet.MutuallyExclusive = IsMutuallyExclusive
  
      If Not (DependentOnSection) = "" Then
          QuestionSet.DependentOnSection = DependentOnSection
      End If
  
      Qsets.Add QuestionSet
      Sections.Item(SectionName).Add Qsets
  
  End Function
  </code></pre>
  
  <p>Then this is called via:</p>
  
  <pre><code>Sub Initilise()
  
      Set Sections = New Collection
  
      DefineSection "PersonalDetails"
      DefineQuestionSet "PersonalDetails", "PersonalDetails", 29, False
  
  End Sub
  </code></pre>