Click to See Complete Forum and Search --> : Calling forms that are opened dynamically


Michelangelo
September 17th, 2001, 02:50 AM
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.

Cimperiali
September 17th, 2001, 04:40 AM
'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