Forum Discussion
Access doesn't close properly. A remaining background process can only be terminated in task manager
- Feb 08, 2022Yes, here also the update available (Europe). Tested en fix the problem. Trusted Location not necessary any more. But I highly recommend it. Otherwise you will have problem starting from April. MS is blocking marcos. Check https://techcommunity.microsoft.com/t5/microsoft-365-blog/helping-users-stay-safe-blocking-internet-macros-by-default-in/ba-p/3071805
JEEDEE23 Thanks for your reply and explanation.
A user will sometimes have multiple access front-ends open at the same time so I needed to taskkill by process ID so the close button only closes the current db. I added this function to a module to get the process ID of the current db (http://allapi.mentalis.org/apilist/GetCurrentProcessId.shtml_:
Declare Function GetCurrentProcessId Lib "kernel32" Alias "GetCurrentProcessId" () As Long
Our Infosec group doesn't allow us to call cmd.exe so I used powershell instead to call taskkill:
Shell ("powershell taskkill.exe /f /t /PID " & GetCurrentProcessId)I noticed that sometimes the lock file does close? Maybe the slight delay sometimes when calling the shell allows the Application.Quit or DoCmd.Quit to complete and close the lock file?
Another variation on the same theme
I have an analyzer app that checks on the properties of external Access databases using automation.
To ensure the background Access process is terminated when I close the analyzer (or change to view details of another database, I use WMI to kill that Access instance:
'kill any existing instances of appAcc & hence leftover instances of Access in task manager
'this causes error 91 if appAcc not yet created e.g. when form first loaded
'use error handling in such cases
30 With appAcc
40 .CloseCurrentDatabase
50 DoEvents
60 If Application.hWndAccessApp = appAcc.hWndAccessApp Then WMI_KillProcess "MsAccess.exe"
70 DoEvents
80 .Quit
90 DoEvents
100 End With