Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Removing a form from memory

Posted on 1999-08-20
Medium Priority
Last Modified: 2010-04-30
I have a form in VB 6 which has several text boxes and combo
boxes on it.  When I exit this form I do a "unload me" and a "set frmapp = nothing".  The problem is that when I load the form again later in the program the data that was in it when I unloaded it is still there.  
The easy way to solve this problem is to write a procedure
that clears out all of the text boxes, but I thought unloading it and setting it to nothing would automatically do that.  
Any thoughts or suggestions would be great.
Question by:jtjcomp
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 18

Expert Comment

ID: 1532731
Where is the code where you are setting the frmApp = Nothing?  If it is inside of the frmApp, it may be possible that the form can't entirely be unloaded, as you're still executing code within that form.  Is this form modal?  If so, then you can hide it, which will then return control to the place in code where you first showed it modally, and on the next line you can unload it, then set it to nothing.

If it's not shown modally, you might try moving the set frmApp = nothing in the Unload event of the form frmApp.

Accepted Solution

Juilette earned 200 total points
ID: 1532732
'put your set form = nothing before the unload
'and If all else fails

'if you have only one form this will work fine in a click event
  Dim myCtrl as control
  For Each myCtrl In Me.Controls
      If TypeOf myCtrl Is TextBox Then
            myCtrl.Text = ""
      End If
    unload me

LVL 15

Expert Comment

ID: 1532733
>the data that was in it when I unloaded it is still there
Not possible. You never Unloaded that form.

Setting form to nothing will clear all controls and form variables.
Unloading form will clear all controls, but form variables will still be in memory:

' Form1 code
Option Explicit

Private Sub Form_Load()
    Dim x As New Form2
    Load x ' this will load form2
    ' set form2 variable
    x.myVar = "www"
    ' set form2 text1.text
    x.Text1.Text = "wwwwwwwwww"
    Unload x
    Debug.Print "after unload: "
    Debug.Print x.myVar ' unload will not myVar from memory
    Debug.Print x.Text1.Text ' unload will clear textbox
    Set x = Nothing ' this will clear both form2 variables and controls
End Sub

' Form2 code, add textbox Text1
Option Explicit
Public myVar As String

Private Sub Form_Load()
End Sub


Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses

704 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question