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.
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).
Is it possible to use the same method to add collections to collections or would I have to define each collection explictly?
Code in Module:
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
Then this is called via:
Sub Initilise()
Set Sections = New Collection
DefineSection "PersonalDetails"
DefineQuestionSet "PersonalDetails", "PersonalDetails", 29, False
End Sub