Results 1 to 4 of 4

Thread: how to create new form while executing

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2013
    Posts
    91

    how to create new form while executing

    hi bro am working on listbox and i want your help. i want to know how to create new form while executing the tool. like
    i have a list of items. when i select any of them a new form show(create)

  2. #2
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: how to create new form while executing

    Here's an example:

    Code:
    Option Explicit    'Paste this in a blank Form
    
    Private WithEvents List1 As VB.ListBox
    
    Private Sub Form_Load()
        Caption = "Click the ListBox's 1st item."
    
        Set List1 = Controls.Add("VB.ListBox", "List1")
        With List1
            .AddItem Name
            .Move (ScaleWidth - .Width) * 0.5!, (ScaleHeight - .Height) * 0.5!
            .Visible = True
        End With
    End Sub
    
    Private Sub List1_Click()
        Forms.Add(List1.List(List1.ListIndex)).Show
    End Sub
    Remember, it's just an example. Study how it works so you can adapt it to your real code.
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  3. #3
    Fanatic Member
    Join Date
    Jan 2013
    Posts
    764

    Re: how to create new form while executing

    Forms and other Controls are 'Load'ed at run-time, not created.
    Code:
    Private Sub ListBox1_KeyDown(KeyCode As Integer, Shift As Integer)
    
       If ( KeyCode = vbKeyReturn ) Then 
    
          Select Case ListBox1.Text
          Case "Form 6"
             Load Form6
             Form6.Show 
    
          End Select 
       End If 
    
    End Sub
    I wouldn't put this code on Click (item selected) event, because that will get fired every time you move up or down the list.

    Regards, Phill W.

  4. #4
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: how to create new form while executing

    Well you can create a copy of a form at runtime if that is what you mean

    Code:
    Dim NewForm as Form
    Set NewForm=New Form1
    NewForm.Show

Posting Permissions

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



Click Here to Expand Forum to Full Width