Help! Access won't close - have to end task

brian.naille

New member
Local time
Today, 13:01
Joined
Mar 1, 2010
Messages
1
I am a newbie to this forum and am hoping any of you can help. I have a MS Access 2003 mdb which is giving me fits. The issue I am getting is that when you try to close the db, it will exit the database but NOT MS Access. You are left with an Access empty window which will not exit and has to be end tasked.

I've looked at a bunch of forums and found suggestions about objects that need to be closed before closing the db. I tried that to no avail - I wrote a function that cycles through and closes all objects (forms, modules, workspaces, databases, recordsets, etc.). The first time I tracked this error down, I finally found the problem to be with a certain global variable. Once it got assigned, the app wouldn't close. So, I wrote a work-around and voila! But, now it's back again.

I have now added a section that nullifies all of my global variables (actually they are "public" not "global") but it doesn't seem to help either.

Is there any way I can figure out what resource is hanging on and keeping Access from properly closing? I don't think you can trigger an end task from VBA but it's sure tempting since my head is getting sore from banging against my desk. ANY suggestions would be appreciated (aside from quitting my job and taking up crochet).

Thanks!
 
Code:
Application.Quit

Put that in the button's event that closes the database. That is if you have a custom button.

Go through your code and remember to set any objects you've created to Nothing.
 
Make sure you are using Application.Quit, if you are using that and Access still won't close you can try placing this API into a public module and calling it in your close function.

You can get the handle using Application.hWndAccessApp

Code:
Public Declare Function EndTask Lib "user32.dll" (ByVal hWnd As Long, ByVal fShutDown As Boolean, ByVal fForce As Boolean) As Long

Example call

Code:
Sub test()
dim hWnd as long
 
hwnd = Application.hWndAccessApp
 
Call EndTask(hwnd,false,true)
 
end sub
 
make sure any recordsets you have are closed and set to nothing

make sure that any instances of external objects like excel are set to nothing.

it may be this sort of thing, causing the problem.
 
That was what I was thinking too Dave. These objects do take up memory if not used sparingly and not closed after use.
 
1. Make a backup.
2. Compact/Repair
3. Make a backup.
4. Decompile.
5. Make a backup.
6. Create a new database container and import everything.
7. Make a backup.
8. If that doesn’t work, post a zipped (<780KB) attachment.
9. Did I mention; make a backup.
 

Users who are viewing this thread

Back
Top Bottom