Close one form and open another-VBForums
Results 1 to 6 of 6

Thread: Close one form and open another

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jun 2010
    Posts
    19

    Close one form and open another

    When I open my application I have the first form which opens as the Register form. When I press the Activate Button I want the MAIN form to open and I am using the code below as the last two line:

    Main.ShowDialog()
    Me.Close()

    When the main form opens the Register form does not close and stays background.

    If I close:

    me.close()
    main.showdialog()

    then the whole application closes.

    Any help on this matter?

  2. #2
    Super Moderator Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,335

    Re: Close one form and open another

    Since Main.ShowDialog() would cause VB6 to yak all over itself, I suspect you are using VB.NET.

    Moved
    Please use [Code]your code goes in here[/Code] tags when posting code.
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    I dont answer coding questions via PM or EMail. Please post a thread in the appropriate forum section.

    Creating A Wizard In VB.NET
    Paging A Recordset
    What is wrong with using On Error Resume Next
    Good Article: Language Enhancements In Visual Basic 2010
    Upgrading VB6 Code To VB.NET
    Microsoft MVP 2005/2006/2007/2008/2009/2010/2011/2012/Defrocked

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jun 2010
    Posts
    19

    Re: Close one form and open another

    Yes this is Vb.Net. Am I in the wrong place?

  4. #4
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    2,424

    Re: Close one form and open another

    Hi Mohdali, you are in the right place now! There are two things you need to change.

    First, you must use Main.Show instead of Main.ShowDialog. Otherwise, your first form can't close until after Main closes.

    Second, you need to go to the project properties, and change the Shutdown mode (near the bottom of the Application tab) from "when startup form closes" to "when last form closes".

    BB

  5. #5
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    2,424

    Re: Close one form and open another

    [sorry, accidentally posted twice]
    BB

  6. #6
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    87,850

    Re: Close one form and open another

    Also, you MUST Show the new form BEFORE you Close the current form. If you Close the current form first then the last form will have closed at that point and the app will exit.

    2007-2014

    Why is my data not saved to my database? | MSDN Data Walkthroughs
    MSDN "How Do I?" Videos: VB | C#
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts) | WP8 Turnstile Feather Transition with Pivot Control
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.