Closing all forms at once

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Adam Honek

    #1

    Closing all forms at once

    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.Ope nForms

    aForm .Close()

    Next



    Where should this be? I put it in form_deactivate d() 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


  • R. MacDonald

    #2
    Re: Closing all forms at once

    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.Ope nForms.Count > 0
    Close(Applicati on.OpenForms(0) )
    Loop

    instead.

    Cheers,
    Randy


    Adam Honek wrote:[color=blue]
    > 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.Ope nForms
    >
    > aForm .Close()
    >
    > Next
    >
    >
    >
    > Where should this be? I put it in form_deactivate d() 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
    >
    >[/color]

    Comment

    Working...