其他人在退出数据库时遇到MSACCESS.EXE进程未关闭(从任务管理器)的问题。我读过的每篇帖子都与未正确关闭记录集变量有关。
当我退出正在处理的数据库时,我注意到MSACCESS.EXE进程从Win 10任务管理器中的“应用程序”部分移动到“后台进程”。这个挂起过程继续利用RAM。我确定我正在正确关闭所有记录集变量。
通过大量调试,我找到了一种复制问题的简单方法:
在打开弹出属性设置为True的表单后,每次关闭数据库时,其他MSACCESS.EXE进程都会在任务管理器中挂起。
我的数据库使用大量弹出窗体。我应该如何关闭我的数据库,以便这些挂起的进程不会堆叠? (我在Windows 10中使用Access 2013.)
谢谢, 萨姆
答案 0 :(得分:0)
您现在如何关闭数据库?
您可以更改命令以调用函数。 然后在该函数中调用一个关闭所有打开表单的例程 您可能必须添加参数才能关闭而不保存 - 具体取决于您的结果。
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
来自http://www.devhut.net/2015/02/17/ms-access-vba-close-all-open-forms/
答案 1 :(得分:0)
在新的示例数据库中尝试这个非常基本的示例。
编辑:在每个关闭表单后添加Sleep
和DoEvents
,以防缓存/快速CPU超前代码?最后一次尝试解决奇怪的问题。
在第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
使用两个命令按钮创建基本
Form1
: 命令按钮Command1
(Caption =打开弹出窗体) 命令按钮Command0
(Caption =退出DB)
在Form1的表单模块中粘贴文本
'------------------------------------------------------------
' 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
创建另一个表单
添加命令按钮Form2-popup
并将Popup属性设置为true 使用标题"退出表单"Command1
'------------------------------------------------------------
' 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