Glory
Well-known Member
- Joined
- Mar 16, 2011
- Messages
- 640
Here's the problem. I'm trying to get a checkbox created at runtime to adda new page to a multipage object, which is also created at runtime.
The object variable associated with the multipage object won't survive between calls of two separate subs in the class module I'm using. It appears as nothing in a later sub despite being set in an earlier sub.
This example uses a blank userform called "userform2" and a class module called "class2":
Userform2 object module code:
Class2 module code:
Please help me out with this.
The object variable associated with the multipage object won't survive between calls of two separate subs in the class module I'm using. It appears as nothing in a later sub despite being set in an earlier sub.
This example uses a blank userform called "userform2" and a class module called "class2":
Userform2 object module code:
Code:
Public Mult, mp As Object
Private checker2, mp1 As Class2
Private Sub UserForm_Initialize()
Dim checker1 As MSForms.CheckBox
Set checker1 = Me.Controls.Add("forms.Checkbox.1")
With checker1
.Height = 22
.Left = 6
.Top = 12
.Width = 72
.Name = "CheckBox1"
.Caption = "CheckBox1"
End With
Set checker2 = New Class2
checker2.Init checker1
Set mp = Me.Controls.Add("forms.Multipage.1")
With mp
.Height = 40
.Left = 6
.Top = 40
.Width = 100
.Pages.Remove (1)
End With
Set mp1 = New Class2
mp1.Init2 mp
End Sub
Class2 module code:
Code:
Public Mult As Object
Private WithEvents cb As MSForms.CheckBox
Public Sub Init(ByVal CBox As MSForms.CheckBox)
Set cb = CBox
End Sub
Public Static Sub Init2(ByVal Multi As MSForms.MultiPage)
Set Mult = Multi
If Not IsEmpty(Mult) Then: MsgBox Mult.Name
End Sub
Public Sub cb_Click()
If cb.Value = True Then
If Not Mult Is Nothing Then: MsgBox Mult.Name
End If
End Sub
Please help me out with this.