While unloading a form using set frm = nothing the form reloads any ideas why?

Posted on 2008-06-09
Last Modified: 2010-04-21

I have several routines to unload an application. The main window is called frm_toolbar. All unloaded fine until I added a timer, I've added code to close the timer before unloading the form and this appears to work ok. But the main form is not unloading, it appears to close but is still running in the background.

If I add set frm_toolbar = nothing the form closes then reloads, if I then clock close it closes and unloads fine. Here is the code I use to initiate the close routines

If unload_main = True Then
Cancel = 0
Cancel = 1
End If

Any ideas appreciated, this is a tricky one.
this is the unload main reoutine. it closes a couple of folders, exits the loop via a exitloopas boolean variable
Source = frm_toolbar.Label3.Caption
'write the current preset calibration value to the ini file
preset_cal = frm_toolbar.txtprecals.text
Call WritePrivateProfileString("Calibration", "Pre_set", preset_cal, filename)
Call WritePrivateProfileString("Calibration", "source", Source, filename)
'delete the temporary file in the application data folder
If IspathExist(temp_folder) Then
Dim fso As New FileSystemObject
Set fso = CreateObject("Scripting.FileSystemObject")
fso.GetFolder (temp_folder)
fso.DeleteFolder (temp_folder), False
'Kill temp_folder
End If
'delete the temporary file in the application data folder
If IspathExist(temp_folder2) Then
Set fso = CreateObject("Scripting.FileSystemObject")
fso.GetFolder (temp_folder2)
fso.DeleteFolder (temp_folder2), False
End If
 'close the open version of image pro
AppActivate image_pro
  Wait 1
SendKeys "%{F4}", True
Wait 0.1
    exitloop = True
    frm_toolbar.Timer1.Interval = 0
    frm_toolbar.Timer1.Enabled = False
 'ensure that all the form have been unloaded
 Dim i As Integer
   For i = Forms.count - 1 To 0 Step -1
      Unload Forms(i)
      Set Forms(i) = Nothing
Exit Function

Open in new window

Question by:eneate
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 21

Expert Comment

ID: 21745681

Author Comment

ID: 21745921
thanks, but I've tried all of those but I still can't get the application to copmpletly unload.
LVL 10

Accepted Solution

cool12399 earned 250 total points
ID: 21746981
Are you setting your timer to .enabled=false?

Whatever your timer code, you need to do something like timer1.enabled=false, before closing the form, otherwise the timer will automatically 'reopen' the form.

Also, make sure you aren't doing anything strange in your query_unload event in your frm_toolbar (i.e., only unloading if an 'x' is clicked on, etc).
LVL 13

Assisted Solution

game-master earned 250 total points
ID: 21748087

good morning...

if you really wanted to close
the application on your timer,
i would rather suggest you to use
the "END" on your timer...

in this case, the application will be closed..


Author Closing Comment

ID: 31465503
Thanks for the feedback. I called a close to an external shell app from within the close routine, this when combined with the timer was the cause of the problem. I've put it into a separate boolean variable and it now all unloads correctly.

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

717 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