Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 200
  • Last Modified:

Cannot Access Form2 again once I close it

I have a form that I open from the Mainform.  When Form2 closes, the MainForm uses that event to trigger some field refreshess.  The issue is, once I close Form2, I cannot open it again.

I reference Form2 from MainForm with this:

Friend WithEvents frmAddParent As New frm_AddParent

Private Sub btn_Parent_Add1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn_Parent_Add1.Click

                frmAddParent.txt_Recode_p.Text = cmb_Recode1.Text
                frmAddParent.Show()

End Sub

Later on I use this:

Private Sub frmAddParent_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles frmAddParent.Closing

...

End Sub

So what I am looking for is a way to still use the Closing Event and beable to open Form2 again.

Thanks.
0
tobey1
Asked:
tobey1
  • 3
  • 2
2 Solutions
 
softplusCommented:
I'm not sure if you mean this, but it's a way:
Private Sub frmAddParent_Closing(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles frmAddParent.Closing
.... do whatever you want
            e.Cancel = True ' will keep the form from closing

End Sub

What you can't do however, is reopen the same form you are processing the Closing event for (wouldn't make much sense, usually).

Is that about what you were looking for?
John
0
 
tobey1Author Commented:
Almost....What I need, and it may not be possible is that Once I am done (close) with Form2 (frm_AddParent).  The need may arise that I need to reopen that form again to do additional work.  Now I do want to Close From2 as I do not need that on the screen any more, unless I need to goback to it.  This is a rare occation, but I would hate to have to Close my entire application so that I can Open that form again.
0
 
softplusCommented:
Ah, in that case it's no problem at all, just open it the same you you did the first time.
i.e.
        Dim frm As Form2 = New Form2
        frm.ShowDialog() ' or .Show()

if the last one was closed it doesn't matter, as you are really making a new "copy" of the form here.

John
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
tobey1Author Commented:
When I add that  into my code, the _Closing Event nolonger functions, so my mainform is not getting updated with the information from Form2.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Like this:

    Friend WithEvents frmAddParent As New frm_AddParent

    Private Sub btn_Parent_Add1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn_Parent_Add1.Click
        If frmAddParent Is Nothing Then
            frmAddParent = New frm_AddParent
        End If

        frmAddParent.txt_Recode_p.Text = cmb_Recode1.Text
        frmAddParent.Show()
    End Sub


    Private Sub frmAddParent_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles frmAddParent.Closing

        ' code...

        frmAddParent = Nothing      ' <---------------------------
    End Sub
0
 
tobey1Author Commented:
Thanks Guys!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now