Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleUnload a form and clear the variables it contains
Keywordsforms, unload, clear, variables
CategoriesTips and Tricks
 
Forms have two parts: a visible part and an invisible part. The visible part is what you see on the screen. The invisible part holds the form's variables.

When you use Unload to unload a form, the visible part is destroyed but the invisible part is not. If you redisplay the form, its variables have the same values they did when you unloaded the form.

To clear the form's variables, set the reference to the form object to Nothing. Do this even if you are using the special instance of the form named after itself, even though that doesn't seem to make sense. Later you can use the special instance variable to redisplay the form with reset values.

 
' Show Form2.
Private Sub Command1_Click()
    Form2.Show
End Sub

' Unload the form's visible component only.
Private Sub Command2_Click()
    Unload Form2
End Sub

' Unload the form's visible and invisible components.
Private Sub Command3_Click()
    Unload Form2
    Set Form2 = Nothing
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated