Results 1 to 5 of 5

Thread: [RESOLVED] Working with multiple copies of a form?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2013
    Location
    Albania
    Posts
    101

    Resolved [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.

  2. #2
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: Working with multiple copies of a form?

    Is this what you want?

    vb Code:
    1. Option Explicit
    2. Dim frmNT, frm1 As New Form1
    3. Private Sub cmdLaunch_Click()
    4. frmNT.cmdLaunch.Caption = "Edit"
    5. frmNT.Show
    6. frmNT.Text.Visible = False
    7. If frmNT.cmdLaunch.Caption = "Edit" Then
    8.    frm1.Text = "hello"
    9.     frm1.Show
    10.     frm1.cmdLaunch.Visible = False
    11. Else
    12.    frm1.Hide
    13. End If
    14. End Sub
    15.  
    16. Private Sub Form_Load()
    17. Set frmNT = Form1
    18. End Sub
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Feb 2013
    Location
    Albania
    Posts
    101

    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?

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

    Re: Working with multiple copies of a form?

    Quote Originally Posted by kevinKZzaka View Post
    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 View Post
    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
    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)

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Feb 2013
    Location
    Albania
    Posts
    101

    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.

Tags for this Thread

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