Closing all forms at once

  • Thread starter Thread starter Adam Honek
  • Start date Start date
A

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
 
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
 
Back
Top