Home All Groups Group Topic Archive Search About

Closing all forms at once

Author
12 May 2006 4:41 AM
Adam Honek
I'm using the below code but having little luck even though
it looks right to me:

Dim aForm As Form

For Each aForm In Application.OpenForms

aForm .Close()

Next



Where should this be? I put it in form_deactivated() and nothing, same for
form_finalize().

In VB6 I believe it was form_closing but that's no longer available in
VB.NET.



Thanks,

Adam

Author
12 May 2006 6:39 AM
R. MacDonald
Hello, Adam,

You don't say exactly what problem you are experiencing with this, but I
suspect that the difficulty is that closing the form removes it from the
OpenForms collection, and this in turn disrupts the iteration.

Try something like:

     Do While Application.OpenForms.Count > 0
         Close(Application.OpenForms(0))
     Loop

instead.

Cheers,
Randy


Adam Honek wrote:
Show quoteHide quote
> I'm using the below code but having little luck even though
> it looks right to me:
>
> Dim aForm As Form
>
> For Each aForm In Application.OpenForms
>
> aForm .Close()
>
> Next
>
>
>
> Where should this be? I put it in form_deactivated() and nothing, same for
> form_finalize().
>
> In VB6 I believe it was form_closing but that's no longer available in
> VB.NET.
>
>
>
> Thanks,
>
> Adam
>
>