Link to home
Start Free TrialLog in
Avatar of kalyani_g
kalyani_g

asked on

CLOSING FORMS IN VB

how to close all opened forms in VB at time?
Avatar of SNilsson
SNilsson
Flag of Sweden image

Dim x as form

For each x in forms
   unload x
Next
Avatar of qwertykeyboard
qwertykeyboard

There are 2 possibilities. You can:

unload form?

that will close the form HOWEVER... this will hide the form:

form?.hide

Good Luck
If you have hundreds of forms, then you might not want to use either of those possibilities!!!
If he have hundreds of forms, he have a design problem.
Avatar of Mike McCracken
Why is having hundreds of forms a design problem?

mlmcc
Well, hundreds of open forms then... imagine the poor user's when he look at the interface, I cant see any situation where it would be neccesary to have hundreds of forms, instancing one form a hundred times, that I could understand.
If you mean all open at the same time I agree.  We have an application with nearly 100 forms each with a specific purpose and there is no confusion since generally only one or two are open at a time.

mlmcc
close or hide?
or you want to make sure the application exits when the form is close irrespective of some forms being open?
if its the last ie u wnat the app to quit irrespective of some forms being open on the main use END
See, you may write code as

public sub CloseAll()
    Dim i As Integer
   
    Dim x As Object
   
    For i = Forms.Count To 1 Step -1
       
        Set x = Forms(i - 1)
        Unload x
        Set x = Nothing
       
    Next

End Sub

Hope it helps.
Please proceed. . .

As a suggestion, closing a form, even a hundred or so can be done without a coding . If and only if you have design it to have a parent form or MDIform. The other forms MDIChild property should be set to true. Unloading the parent form will automatically unload all open child forms. . .leaving independent forms still running if the author wants it that way. (Abcourse avoiding END command in the parent form)

Another thing is that the author did not mentioned closing all open forms without ending the application. .  So whats the problem? Invoking END command will automatically close all open forms then End the application. Anyway the author might need to elaborate further his question. . Sorry if I misunderstood.
ASKER CERTIFIED SOLUTION
Avatar of CetusMOD
CetusMOD
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial