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

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).

Who is Participating?
Mike TomlinsonMiddle School Assistant TeacherCommented:
???  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
omsudhaAuthor Commented:
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-

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.