Consulting

Results 1 to 3 of 3

Thread: Passing variables inside the dynamically created form

  1. #1
    VBAX Regular
    Joined
    Dec 2011
    Posts
    58
    Location

    Passing variables inside the dynamically created form

    hi there

    I've got one issue here I couldn't find a solution. I create a UserForm dynamically.
    [VBA]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[/VBA]

    Would be happy to any hints,

    Thanks in advance

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [VBA] With MetaParList.CodeModule
    Line = .CountOfLines
    .insertlines Line + 1, "Sub OKButton_Click()"
    .insertlines Line + 2, "MsgBox " & testcase
    .insertlines Line + 120, "End Sub"
    End With
    [/VBA]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Regular
    Joined
    Dec 2011
    Posts
    58
    Location
    Hi xld,
    thanks for a quick reply...

    That did the work!!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •