Modal Forms Are Not Closed, When The Main Application Is Closed

Posted on 2006-06-02
Last Modified: 2010-04-07
Hi All,

I have few modal forms in my application. For Some Reasons(which are necessary for my application), I have used

<form>.show                  instead of
<form>.show 1
But the problem is that in such a case, if the user opens such form and forgget to close them and closes the main application these forms remain there unclosed.

What can be the solution that as soon I closes the main application (all forms opened including Modal opened with <.show> also closes).

Question by:omsudha
    LVL 85

    Accepted Solution

    ???  Your post seems to have conflicting information in it...

    If you have shown the forms modally, then you can't interact with the main form until the modal form is closed.

    This line:   (which you say you're using)


    does NOT show a form modally.  

    This does show a form modally:

        <form>.Show vbModal

    You could try code like this in your main form to make all forms unload when it is closed:

        Private Sub Form_Unload(Cancel As Integer)
            Dim frm As Form
            For Each frm In Forms
                Unload frm
            Next frm
        End Sub

    Author Comment

    Thanks Idle_Mind,
    Let me clear first-

    Those are modal forms with their MDIChild is False in Design, if that value is True the form would have closed auto when the main application is closed.

    But the above form I have showed using
    .Show instead of .show 1(vbModal)
    If 2nd is the case I would not be able to interact with the main application till the form is
    close, but since I have used <form>.show and also its MDIChild is False, I was facing the above problem.

    However in any case your code snippet will solve my problem.
    I have one more question if you can have a look and see at-


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
    This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
    Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now