How do you unload forms from within your code. And I dont mean HIDING them.
thanks,
Wick
Printable View
How do you unload forms from within your code. And I dont mean HIDING them.
thanks,
Wick
Use the Unload method
Code:'Will unload Form2
Unload Form2
'Will unload the current Form you are in
Unload Me
You are best to free up any resources in use from your program as well. You can do this by unloading all forms:
Or just one:Code:Public Sub UnloadAllForms()
Dim OfTheseForms As Form
For Each OfTheseForms In Forms
Unload OfTheseForms
Set OfTheseForms = Nothing
Next OfTheseForms
End Sub
Code:Unload Form1
Set Form1 = Nothing
Forms are funny things in VB...
They are in reality "Classes" and the second you show your form it has actually created an instance.
The problem then is you cannot get rid of the actual forms themselves unless you actually created a NEW instance of them and use it.
As Matthew said above, if you "Dim" an instance of your form, use it, unload it and then set it to nothing you have successfully gotten rid of every last trace of the form from memory.
If however you just started using the form by calling its name directly you will have that form hanging around and although you can unload it I am not sure if you can set it to nothing....
People often get confused with VB5 and VB6 thinking that forms are some "special" kind of entity when they are really classes... As many people don't understand object-orientation and classes they fail to understand how forms REALLY work.