PDA

View Full Version : Passing variables inside the dynamically created form



lionne
07-04-2012, 03:30 AM
hi there

I've got one issue here I couldn't find a solution. I create a UserForm dynamically.
Set MetaParList = Application.VBE.ActiveVBProject.VBComponents.Add(3)

With MetaParList
'some code here, where the value of variable testcase will be set, let's say
testcase = 5
'Then I create a button here
Set OKButton = MetaParList.Designer.Controls.Add("Forms.CommandButton.1")

With OKButton
.Name = "OKButton"
.Caption = "OK"
.Width = 100
.Top = grp_height + 50
.Left = 350
End With

'Here is the code for OK-Button
With MetaParList.CodeModule
Line = .CountOfLines
.InsertLines Line + 1, "Sub OKButton_Click()"
'Here I need to use the testcase value, but how to pass it?
.InsertLines Line + 120, "End Sub"
End with
End with

Would be happy to any hints,

Thanks in advance

Bob Phillips
07-04-2012, 04:02 AM
With MetaParList.CodeModule
Line = .CountOfLines
.insertlines Line + 1, "Sub OKButton_Click()"
.insertlines Line + 2, "MsgBox " & testcase
.insertlines Line + 120, "End Sub"
End With

lionne
07-04-2012, 04:35 AM
Hi xld,
thanks for a quick reply...

That did the work!!!