I am trying to generate a offline Questionnaire form which is a series of surveys that contain questions with sub parts. Hence I need to loop through a db recordset to get back my questions and generate a form with all of the controls on it.
The problem I face is generating them dynamically and then validating them.
This code seems to work fine until it is placed within a recordset loop
'code on my userform is named UserForm1:
Dim OB_Coll As Collection
Dim Pos As Integer
Private Sub cmdEvent_Click()
Dim o As MSForms.OptionButton
Dim OBE As New OptionButtonEvents
If OB_Coll Is Nothing Then Set OB_Coll = New Collection
Set o = Me.Controls.Add("Forms.OptionButton.1", , True)
o.Caption = "Dynamically Added Option Button" & CStr(Me.Controls.Count) - 2
o.AutoSize = True
o.Top = Pos
Call OBE.WatchControl(o, Me)
Pos = Pos + o.Height + 4
Friend Sub OptionButtonDblClick(o As MSForms.OptionButton)
MsgBox o.Name & " was just double-clicked..."
'code on a new class module named OptionButtonEvents
Private WithEvents ob As MSForms.OptionButton
Private CallBackParent As UserForm1
Private Sub ob_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Friend Sub WatchControl(oControl As MSForms.OptionButton, oParent As UserForm1)
Set ob = oControl
Set CallBackParent = oParent
Can anybody tell me what I would need to do to get it working in a loop.
Would I have to use the EVAL function?