[RESOLVED] Working with multiple copies of a form?
I am making a notes app. There is a form, which is the parent, the example, the form that all the new ones are going to be a copy of, and has a textbox in it. It's called frmExample.
I use: dim newNt as new frmExample , to create a new copy of frmExample.
frmExample has a command button(meaning that all the copies will have a command button too) that launches a new form called frmEdit.
In frmEdit, there is a command button. I want that when the user clicks the command button in frmEdit, it will modify the value of the textbox of the form that the first command button has been clicked. So logically it would be: newNt.text1.text = "hello"
But this doesn't work.
So I just want to change the value of the textbox in the form that launched the frmEdit. How can I do this?
I have been around this problem for a long time now, and couldn't find a solution. Thanks.
Re: Working with multiple copies of a form?
Is this what you want?
vb Code:
Option Explicit
Dim frmNT, frm1 As New Form1
Private Sub cmdLaunch_Click()
frmNT.cmdLaunch.Caption = "Edit"
frmNT.Show
frmNT.Text.Visible = False
If frmNT.cmdLaunch.Caption = "Edit" Then
frm1.Text = "hello"
frm1.Show
frm1.cmdLaunch.Visible = False
Else
frm1.Hide
End If
End Sub
Private Sub Form_Load()
Set frmNT = Form1
End Sub
Re: Working with multiple copies of a form?
Actually, not really. I think you misunderstood the question(probably because I didn't explain it very well).
I found this here on vbforums: (http://www.vbforums.com/showthread.p...ces+Form,+How?)
Dim frm As form
Dim i as integer
i=i+1
Set frm = New Form1
frm.Tag = "New_Form_" & i
frm.Show
This solves a huge problem, but it creates another one. How do I unload the form with a specific tag? There is another. Each time I double click that, it uses the code above to create new instancies of frmExample. There is also an integer "i" whose value adds by 1 everytime I double click the other form. So, each frmExample copy's tag is like "New_Form_1" " New_Form_2" "New_Form_3" etc...
But how do I unload, let's say, "New_Form_3" from a command button that is on another form?
Re: Working with multiple copies of a form?
Quote:
Originally Posted by
kevinKZzaka
How can I do this?
Perhaps the following code snippet might work:
Code:
'In parent Form
Private Sub Command1_Click()
With New frmExample
.Show
End With
End Sub
Code:
'In frmExample
Private Sub Command1_Click()
Set frmEdit.Owner = Me
frmEdit.Show
End Sub
Code:
'In frmEdit
Public Owner As frmExample 'Custom public property
Private Sub Command1_Click()
Owner.Text1 = "hello"
End Sub
Quote:
Originally Posted by
kevinKZzaka
But how do I unload, let's say, "New_Form_3" from a command button that is on another form?
Take advantage of the Forms Collection! Example:
Code:
Private Sub Command2_Click() 'This code assumes there are 4 Forms currently loaded
Unload Forms(3) 'This line unloads the 4th (last) Form
End Sub 'Make sure that the Index < Forms.Count
You can access any property/method of the referenced Form using the dot operator:
Code:
Forms(3).Property
Forms(3).Method
Re: Working with multiple copies of a form?
Thank you Bonnie West. That was very informative, but I actually solved the problem following the example of another friend similar to this, here on vbforums.