- Local time
- Today, 21:52
- Joined
- Feb 19, 2013
- Messages
- 17,669
I have an app which creates an Access instance and populates it with another db that the user selects for analysis. Even if I do nothing and then close the instance it remains in memory. It was reported as a bug about 3 years ago (although that seems to be more about closing access in general, not a separate instance). And was fixed back then.
I'm using 365 64bit Office and the app itself appears to be closed and the lockfile gone, it's just the instance remains in memory. This is the code to open/close the instance and assign a db. The only modification is to disable the accApp minimize and close buttons if the user were to open it to view.
I've had lengthy 'conversations' with AI but they are unable to provide a valid solution. Much talk of leaving form/report references open,
This is the code to open/close accApp - copy and paste it to a db of your choice and supply a dbName (to include path). Have task manager open to see what happens on creation and destruction. When choosing a db, ensure you do not have a startform specified and autoexec macro is disabled. to ensure no code runs
code to use (even from the immediate window)
CloseOpenDB "C:\path\dbname.accdb"
CloseOpenDB ""
So is anybody doing something like this - from a 'master' Access app, opening a db in another access instance created in the master app? If so, do you experience the same issue? If not, would you mind sharing your solution for opening/closing the app?
And if someone would like to try the above code - do you experience the same issue?
Edit - connecting via DAO does not cause an issue, but this app is looking at the objects rather than the data and the objects cannot be analysed from DAO
I'm using 365 64bit Office and the app itself appears to be closed and the lockfile gone, it's just the instance remains in memory. This is the code to open/close the instance and assign a db. The only modification is to disable the accApp minimize and close buttons if the user were to open it to view.
I've had lengthy 'conversations' with AI but they are unable to provide a valid solution. Much talk of leaving form/report references open,
This is the code to open/close accApp - copy and paste it to a db of your choice and supply a dbName (to include path). Have task manager open to see what happens on creation and destruction. When choosing a db, ensure you do not have a startform specified and autoexec macro is disabled. to ensure no code runs
Code:
Public accApp As Access.Application
Sub CloseOpenDB(dbName As String)
Static oldName As String
Dim lStyle As LongPtr
Dim frm As Object
If dbName = "" Then 'close accApp
If Not accApp Is Nothing Then
If Not accApp.CurrentDb Is Nothing Then 'close db
'If Not accApp.CurrentProject Is Nothing Then 'close db
For Each frm In accApp.CurrentProject.AllForms
If accApp.SysCmd(acSysCmdGetObjectState, acForm, frm.Name) = acObjStateOpen Then
accApp.DoCmd.Close acForm, frm.Name
End If 'accApp.SysCmd....
Next frm
Set frm = Nothing
accApp.CloseCurrentDatabase
End If 'Not accApp.CurrentDb Is Nothing
accApp.Quit acQuitSaveNone
'accApp.DoCmd.Quit acQuitSaveNone (no difference with either option)
DoEvents
Set accApp = Nothing
DoEvents
Debug.Print accApp Is Nothing
End If 'Not accApp Is Nothing
oldName = ""
Exit Sub
End If 'dbName = "" (close instance)
'****** Open a new db ******
If dbName <> oldName Then
If accApp Is Nothing Then 'open accApp
Set accApp = New Access.Application '***************** at this point the app appears in background processes in task manager
accApp.AutomationSecurity = 3 'msoAutomationSecurityForceDisable
'accApp.Visible = False 'default, change to true if you wish - in which case it moves to the Apps section in task manager
'********************** the following code can be commendeted out for testing - otherwise add in the relevant API's and constants
' 'disable close button
RemoveMenu GetSystemMenu(accApp.hWndAccessApp, False), SC_CLOSE, MF_BYCOMMAND
DrawMenuBar accApp.hWndAccessApp
' Remove Minimize button
lStyle = GetWindowLongPtr(accApp.hWndAccessApp, GWL_STYLE)
lStyle = lStyle And Not WS_MINIMIZEBOX
SetWindowLongPtr accApp.hWndAccessApp, GWL_STYLE, lStyle
SetWindowPos accApp.hWndAccessApp, 0, 0, 0, 0, 0, _
SWP_NOMOVE Or SWP_NOSIZE Or SWP_NOZORDER Or SWP_FRAMECHANGED
'****************************** comment out to here
ElseIf dbName <> accApp.CurrentDb.Name Then
accApp.CloseCurrentDatabase
End If 'accApp Is Nothing
DoEvents
End If 'dbName <> oldName
'assign new db
accApp.OpenCurrentDatabase dbName, False
accApp.UserControl = False
oldName = dbName
End Sub
code to use (even from the immediate window)
CloseOpenDB "C:\path\dbname.accdb"
CloseOpenDB ""
So is anybody doing something like this - from a 'master' Access app, opening a db in another access instance created in the master app? If so, do you experience the same issue? If not, would you mind sharing your solution for opening/closing the app?
And if someone would like to try the above code - do you experience the same issue?
Edit - connecting via DAO does not cause an issue, but this app is looking at the objects rather than the data and the objects cannot be analysed from DAO