Solved

Application not shuting down normally.

Posted on 2002-04-16
12
190 Views
Last Modified: 2010-05-02
I created an application that connects to an Access database using ADO. The problem I have is: If I use the application's File->Exit menu, the apllication always stays in memory. I have to press ALT-CTRL-DEL to end it's task. If I use the control menu (or the X at the top right corner of the form) I get an application error in Windows and the application terminates abnormally. What could be the problem?

The Database connection is declared in the Declarations area as:

  Dim dbConn as New ADODB.Connection

The code in the exit menu is:

Unload Me

My Form_QueryUnlod(Cancel as Integer) event is as follows:

Private Sub Form_QueryUnload(Cancel As Integer)
  If MsgBox("Are you sure you want to exit this application?=vbno Then
  Cancel = True
End Sub

The Form_Unload event contains this code:

Private Sub Form_Unload()
  Dim f As Form
  For Each f in Forms
    If f.Name <> Me.Name then Unload f
  Next
  dbConn.Close
  set dbConn = Nothing
End Sub
0
Comment
Question by:bmatumbura
  • 4
  • 3
  • 3
  • +2
12 Comments
 
LVL 5

Expert Comment

by:rkot2000
ID: 6945349
you may have some global variables in the memory;
try to use this :

Private Sub Form_Unload()
 Dim f As Form
 For Each f in Forms
   If f.Name <> Me.Name then
     Unload f
     set f = nothing
 Next
 dbConn.Close
 set dbConn = Nothing
 set ThisFormObject = nothing
End Sub

or you can add

end before end sub

like this
end
end sub

0
 
LVL 5

Expert Comment

by:rkot2000
ID: 6945355
if you are subclassing your form(s) you need to relase all hooks.
0
 
LVL 5

Expert Comment

by:kcm76
ID: 6945765
If u r using MDI envn., try using **End**. as rkot suggested. This will close all the forms (including Hidden forms) associated with the project workspace.

Otherwise, the problem is to be found out......

0
Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6945845
Do Not use End statement!
Private Sub Form_Unload()
dbConn.Close
set dbConn = Nothing

Dim f As Form
For Each f in Forms
   If f.Name <> Me.Name then Unload f
Next
End Sub
0
 
LVL 5

Expert Comment

by:rkot2000
ID: 6945856
what is wrong with end statement?
True, you need to release remote objects, release connections and end.

it's VERY, VERY bad to use with ActiveX servers(ocx,dll or exe) but it's ok to use with  client exe pc.



It works like garbage collector in Studio Net
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6946022
using End statement is like trying to stop a racer car... against a wall.
"....
....
It works like garbage collector in Studio Net"
Sure it does, so object relesing is done when VB wants to do or when it was time to do or next monday.
Garbage collector from .net not releases object inmediately.
0
 
LVL 2

Expert Comment

by:corvanderlinden
ID: 6947016
This is a nasty problem. I suggest using Numega's smartcheck or something like that. The offending code can be anywhere in your program.

About the End statement

The only case when Visual Basic does not invoke the Class_Terminate event is when you abruptly stop a program using the End command from the Run menu or the End button on the toolbar. This immediately stops all activity in your code, which means that no Class_Terminate event will ever be invoked. If you inserted critical code in the Terminate events—for example, code that releases Windows resources allocated via APIs—you'll experience problems. Sometimes these are big problems, including system crashes. By the same token, NEVER TERMINATE a program using an END STATEMENT in code: This has exactly the same effect, but it's going to create problems even after you compile the application and run it outside the environment.
0
 
LVL 11

Author Comment

by:bmatumbura
ID: 6949878
My project does use a lot of API's. Each form I used has code that sets each object I used to Nothing in the unload event. What amazes me is the Application doesn't crash when run in the IDE. VB does not report any errors either. These errors only occur when I run the create .EXE. How can I trace the execution of code in the application to check at what point the error occurs?
0
 
LVL 2

Accepted Solution

by:
corvanderlinden earned 100 total points
ID: 6950078
Use Numega's tools

http://www.compuware.com/products/numega/index.htm

you could use tracing the execution path of your code to a log file, but I doubt that solves the problem. This is typically a problem where the offending code can be anything (even something that happened at startup time)

What happens if you compile your exe with debugging info. Does the problem then still exists?


0
 
LVL 5

Expert Comment

by:rkot2000
ID: 6950422
re numega: not everybody can pay up to $3000 per numega.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6950505
I am with rkot regarding Numega but in this case, the trial period could be enought.
0
 
LVL 2

Expert Comment

by:corvanderlinden
ID: 6950519
I suggested Numega, because I had a similar problem in our ADO application using Oracle. Also, only failure on application exit on compiled app

All the desk checking and debugging we did, did not take us closer to the solution. Numega's Smartchecker made us aware of a problem in the Oracle db drivers

0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

821 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