CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2001
    Posts
    42

    Calling forms that are opened dynamically

    I've encountered a problem when using the Forms.Add method. When i open the Form this way in runtime, it opens perfectly. But when calling a procedure in this form from another form or module a new window opens, which obviously isn't meant to.
    My code looks like this


    Sub Form1_Load()
    Call OpenForms
    Call EditText()
    End Sub



    Sub EditText()
    Formauto1.Text1.Text = "SomeText"
    End Sub




    Sub OpenForms()
    Dim x as Form, strName as string
    strName = "Formauto1"
    set x = Forms.Add(strName)
    x.Show
    End Sub





    The form FormAuto opens correctly in the procedure OpenForms(). However it opens again when calling procedure EditText().

    Any suggestions.




  2. #2
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: Calling forms that are opened dynamically


    'one solution may be:
    option Explicit
    Dim x as Form
    Dim blnLoaded as Boolean
    private Sub Command1_Click()
    Dim strName as string
    Dim frm as Form ' do not use x here or you will loose pointer to your form
    strName = "Form2"
    for Each frm In Forms
    If frm.Name = strName then
    blnLoaded = true
    End If
    next
    set frm = nothing
    If blnLoaded = false then
    set x = Forms.Add(strName)
    x.Show
    blnLoaded = true
    End If
    EditText
    End Sub

    Sub EditText()
    If blnLoaded then
    x.Text1.Text = "SomeText"
    End If
    End Sub





    Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris, Dr_Micahel
    and all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

    The Rater
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

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

Featured