Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Instance of form

Status
Not open for further replies.

scottsanpedro

Programmer
Apr 26, 2002
97
GB
Hi,
From form1 i'm running a click button event to open an instance of another form I have created. (just playing around) I want to do it by creating an instance of that form and passing a value in.
I have a property let in the other form (frmTest) as this#

Code:
Public Property Let TextValue(txtValue As String)

If Len(txtValue) > 0 Then
    Me.TextClass.Value = txtValue
End If

End Property

and when I click on form1 I have this

Code:
Private Sub Command0_Click()

Dim oFrm As Form_frmTest

Set oFrm = New Form_frmTest

oFrm.TextValue = "ScottNew"

oFrm.SetFocus

End Sub

when I click the frmTest appears and disappears instantly.
How do I get it to stay?
Thanks in advance. Scott
 
The problem you are having is with class lifetime. Since your class(the new form) is instantiated within your subroutine, when the subroutine dies, so do all variables inside of it.

Try moving this declaration statement:
Dim oFrm As Form_frmTest
to the top of your form module instead of inside a routine.

That will make it a class level variable instead of a local variable. I believe that the new form will not disappear until the form calling it is closed.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top