Sam McCoy
Sam McCoy

Reputation: 21

MSACCESS.EXE does not close when using POP-UP forms

Others have had issues with the MSACCESS.EXE process not closing (from Task Manager) when exiting their databases. Each of the posts I've read have had something to do with not properly closing recordset variables.

When I exit the database I'm working on, I notice the MSACCESS.EXE process moves from the "Apps" section to "Background Processes" in Win 10 Task Manager. This hung process continues to utilize RAM. I'm certain that I'm closing all recordset variables properly.

Through a lot of debugging, I figured out a simple way to replicate the problem:

  1. Create two forms in a new Access database. Set the PopUp property to True for one of them and False for the other. Save the forms "PopUp" and "NoPopUp" and close the database.
  2. Open Task Manager to view the processes running on your screen.
  3. Open your Access database and open the NoPopUp form. Note the MSACCESS.EXE process under Apps.
  4. Close your database. Note that MSACCESS.EXE is removed from your list of Processes (both under "Apps" and "Background Processes").
  5. Now reopen your Access database and open form PopUp. Then close the database.
  6. Note that the MSACCESS.EXE process moves from the "Apps" section to "Background Processes" and is still utilizing system memory.

Additional MSACCESS.EXE processes hang in Task Manager each time the database is closed after opening a form with its Pop-up property set to True.

My database uses a ton of Pop-up forms. How should I be closing my database so that these hung processes aren't stacking up? (I'm using Access 2013 in Windows 10.)

Thanks, Sam

Upvotes: 2

Views: 1791

Answers (2)

dbmitch
dbmitch

Reputation: 5386

Try this very basic example in a new sample database.

EDIT: Add a Sleep and DoEvents after every close form in case of caching/fast cpu getting ahead of code? Last attempt to fix weird issue.

In Module 1

Option Compare Database
Option Explicit

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)     

Function CloseAllOpenFrms()

        On Error GoTo Error_Handler
        Dim DbF                   As Access.Form
        Dim DbO                   As Object

        Set DbO = Application.Forms    'Collection of all the open forms

        ' Close all popups first
        For Each DbF In DbO    'Loop all the forms
            If DbF.PopUp Then
                DoCmd.Close acForm, DbF.Name, acSaveNo
                DoEvents
                Sleep 1000
            End If
        Next DbF

        ' Close remaining forms
        For Each DbF In DbO    'Loop all the forms
            DoCmd.Close acForm, DbF.Name, acSaveNo
            DoEvents
            Sleep 1000
        Next DbF

        Application.Quit acQuitSaveNone

    Error_Handler_Exit:
        On Error Resume Next
        Set DbF = Nothing
        Set DbO = Nothing
        Exit Function

    Error_Handler:
        MsgBox "Error closing : " & DbF.Name & vbCrLf & _
               "Error Description: " & Err.Description, _
               vbCritical, "Error closing form"
        Resume Error_Handler_Exit
    End Function

Create basic Form1 with two command buttons: Command button Command1 (Caption= Open Popup Form) Command button Command0 (Caption = Exit DB)

In Form1's form module paste text

'------------------------------------------------------------
' Command1_Click
'
'------------------------------------------------------------
Private Sub Command1_Click()
On Error GoTo Command1_Click_Err

    CloseAllOpenFrms

Command1_Click_Exit:
    Exit Sub

Command1_Click_Err:
    MsgBox Error$
    Resume Command1_Click_Exit

End Sub


'------------------------------------------------------------
' Command0_Click
'
'------------------------------------------------------------
Private Sub Command0_Click()
On Error GoTo Command0_Click_Err

    DoCmd.OpenForm "Form2-popup", acNormal, "", "", , acWindowNormal


Command0_Click_Exit:
    Exit Sub

Command0_Click_Err:
    MsgBox Error$
    Resume Command0_Click_Exit

End Sub

Create another form Form2-popup and set Popup property to true Add command button Command1 with caption "Exit Form"

'------------------------------------------------------------
' Command1_Click
'
'------------------------------------------------------------
Private Sub Command1_Click()
On Error GoTo Command1_Click_Err

    DoCmd.Close , ""


Command1_Click_Exit:
    Exit Sub

Command1_Click_Err:
    MsgBox Error$
    Resume Command1_Click_Exit

End Sub

Upvotes: 0

dbmitch
dbmitch

Reputation: 5386

How are you closing your database now?

Can you change the command to call a function. Then in that function call a routine that closes all open forms You may have to add parameter to close without saving - depending on your results.

Function CloseAllOpenFrms()
    On Error GoTo Error_Handler
    Dim DbF                   As Access.Form
    Dim DbO                   As Object

    Set DbO = Application.Forms    'Collection of all the open forms

    For Each DbF In DbO    'Loop all the forms
            DoCmd.Close acForm, DbF.Name, acSaveNo
    Next DbF

Error_Handler_Exit:
    On Error Resume Next
    Set DbF = Nothing
    Set DbO = Nothing
    Exit Function

Error_Handler:
    MsgBox "The following error has occured." & vbCrLf & vbCrLf & _
           "Error Number: " & Err.Number & vbCrLf & _
           "Error Source: CloseAllOpenFrms" & vbCrLf & _
           "Error Description: " & Err.Description, _
           vbCritical, "An Error has Occured!"
    Resume Error_Handler_Exit
End Function

From http://www.devhut.net/2015/02/17/ms-access-vba-close-all-open-forms/

Upvotes: 0

Related Questions