how to close all forms open?


hello, im making an RPG and i have a pause menu setup to where it shows over the game screen. i have a quit button, and i want to know the code that will make that quit button close all forms. any help will be much appreciated thanks.

If you enjoyed this post, subscribe for updates (it's free)

Better way

Public Sub CloseAllForms()
Dim Frm As Form
Unloadfrms:
Frmlist = ""
For Each Frm In Forms
Frmlist = Frmlist & Frm.Name & vbCrLf
Unload Frm
Set Frm = Nothing
Next
' uncomment line below for debugging
'Msgbox Frmlist
If Frmlist <> "" Then
Goto Unloadfrms
End If
End Sub

Close All Forms

Well its easy enough to close all Forms your app is using with. Just add this Sub to a Module so it can be called from any Form.

Public Sub CloseAllForms()

Dim Frm As Form

For Each Frm In Forms
Unload Frm
Set Frm = Nothing
Next

End Sub

Keith
www.martin2k.co.uk/forums/

I've been programming with VB for 13 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. The supported tag styles are: <foo>, [foo].

More information about formatting options

Type the characters you see in this picture. (verify using audio)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.