Set MDSByYear = ThisWorkbook.VBProject.VBComponents.Add(vbext_ct_MSForm)
MDSByYear.Properties("Caption") = "MDS By Year - Case " & SelCaseCount
MDSByYear.Properties("Height") = (mdsSize + 2) * 25
MDSByYear.Properties("Width") = (maxYear - minYear + 2) * 45 + 40
Randomize
MFName = "UF" & CStr(Int(Rnd * 100000) + 1)
MDSByYear.Properties("Name") = MFName
For loopCount = 1 To mdsSize
Set MDSHandle(loopCount, minYear - 1, SelCaseCount) = MDSByYear.Designer.Controls.Add("forms.frame.1", , True)
With MDSHandle(loopCount, minYear - 1, SelCaseCount)
.Width = (maxYear - minYear + 2) * 45 + 35
.Height = 25
.Top = (loopCount - 1) * 25
.Left = 10
.ZOrder (0)
.Caption = MDSinputs(loopCount)
End With
For YrLoopCount = minYear To maxYear
Set MDSHandle(loopCount, YrLoopCount, SelCaseCount) = MDSHandle(loopCount, minYear - 1, SelCaseCount) _
.Controls.Add("Forms.checkbox.1", , True) 'don't need to use the .designer thing because it's adding a
'control to another control that's already been created
With MDSHandle(loopCount, YrLoopCount, SelCaseCount)
.Width = 44
.Height = 25
.Top = 0 'this is relative to the control that it's been added to
.Left = 10 + (YrLoopCount - minYear) * 45
.ZOrder (0)
.Caption = YrLoopCount
If SelCaseCount > 1 Then
.Value = MDSHandle(loopCount, YrLoopCount, SelCaseCount - 1)
Else
.Value = False
End If
If dataExists(loopCount, YrLoopCount) = False Then .Enabled = False
End With
If SelCaseCount > 1 Then
MDSHandle(loopCount, YrLoopCount, SelCaseCount).Value = _
MDSHandle(loopCount, YrLoopCount, SelCaseCount - 1).Value
End If
Next YrLoopCount
Set MDSHandle(loopCount, maxYear + 1, SelCaseCount) = MDSHandle(loopCount, minYear - 1, SelCaseCount) _
.Controls.Add("Forms.checkbox.1", , True)
With MDSHandle(loopCount, maxYear + 1, SelCaseCount)
.Width = 75
.Height = 25
.Top = 0
.Left = 10 + (YrLoopCount - minYear) * 45
.ZOrder (0)
.Caption = "All Years"
.Value = False
If Not (showYears) Then .Enabled = False
End With
If SelCaseCount > 1 Then
MDSHandle(loopCount, YrLoopCount, SelCaseCount).Value = _
MDSHandle(loopCount, YrLoopCount, SelCaseCount - 1).Value
End If
Next loopCount
Set DoneButton = MDSByYear.Designer.Controls.Add("forms.commandbutton.1", "DoneButton", True)
With DoneButton
.Width = (maxYear - minYear + 2) * 45 + 20
.Height = 25
.Top = mdsSize * 25
.Left = 10
.ZOrder (0)
.Caption = "Done"
.Value = False
End With
With MDSByYear.CodeModule
Line = .CountOfLines
.InsertLines Line + 1, "Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)"
.InsertLines Line + 2, "Cancel = True"
.InsertLines Line + 4, "End Sub"
.InsertLines Line + 5, "Private Sub DoneButton_Click()"
For loopCount = 1 To mdsSize
For YrLoopCount = minYear To maxYear + 1
.InsertLines Line + 10 * (maxYear - minYear + 5) + YrLoopCount - minYear + 1, _
"BootBoolean(" & loopCount & "," & YrLoopCount & "," & SelCaseCount & ") =" _
& "me.checkbox" & (loopCount - 1) * (maxYear - minYear + 1 + 1) + (YrLoopCount - minYear + 1) & ".Value"
Next YrLoopCount
Next loopCount
Line = .CountOfLines
.InsertLines Line + 5, "Me.Hide"
.InsertLines Line + 10, "End Sub"
Line = .CountOfLines
.InsertLines Line + 1, "Private Sub UserForm_Initialize()"
For loopCount = 1 To mdsSize
For YrLoopCount = minYear To maxYear + 1
.InsertLines Line + 10 * (maxYear - minYear + 5) + YrLoopCount - minYear + 1, _
" if BootBoolean(" & loopCount & "," & YrLoopCount & "," & SelCaseCount & ") =" _
& "true then me.checkbox" & (loopCount - 1) * (maxYear - minYear + 1 + 1) + _
(YrLoopCount - minYear + 1) & ".Value=true"
Next YrLoopCount
Next loopCount
Line = .CountOfLines
.InsertLines Line + 5, "End Sub"
End With
MacomSelection.PassTheGDName MFName