Home All Groups Group Topic Archive Search About

newbie stupidity: opening one form and closing another

Author
31 Mar 2005 3:51 PM
lukegregory
I have two forms in my application, the main form (frmMain) and a details
form (frmEditDetails) I have a button on main to open the details form and
close the main form. And the opposite in the details form.

However instead of actually opening one and closing the other it just puts
one over the top. Then when I go from main > details > main I have 3 forms
open.

Using the following code on the Main form:

        Dim Details As New frmEditDetails
        Details.Show()
        Dim Main As New frmMain
        Main.Close()

Please someone tell me how I am going wrong.

Thanks

Author
31 Mar 2005 4:03 PM
Grant Smith
Instead of creating a new instance of your main form, create global
variables one for an instance of your main form and another one for an
instance for your frmEditDetails form.  This way you don't have
multiple instances of each form.  I'd use a module and use the Sub
Main() subroutine to start up your program with something like:

Dim Details as New frmEditDetails
Dim Main as New frmMain

Sub Main()
     Application.Start(Main)
End Sub

And then have two separate subroutines within your module and call them
in the repective forms:

Private Sub ShowDetails()
     Main.Hide()
     Details.Show()
End Sub

Private Sub ShowMain()
    Details.Hide()
    Main.Show()
End Sub

So then just call ShowMain when they click on the details form and
ShowDetail when they click the button on the main form.

Hope this helps
Author
31 Mar 2005 4:27 PM
Cor Ligthert
Luke

The own class is called.

Me.

me.close

I hope this helps,

Cor