你试试这个 '一个窗体 Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer) Me.Visible = False Cancel = True End Sub
是不是数据库没有关闭? 你试试这个:Private Sub Form_Unload(Cancel As Integer) On Error Resume Next Dim ws As Workspace Dim db As Database Dim rs As Recordset For Each ws In Workspaces For Each db In ws.Databases For Each rs In db.Recordsets rs.Close Set rs = Nothing Next db.Close Set db = Nothing Next ws.Close Set ws = Nothing Next End Sub
Public Sub Shutdown(Optional ByVal Force As Boolean = False) '卸载所有窗体 Dim i As Long On Error Resume Next For i = Forms.Count - 1 To 0 Step -1 Unload Forms(i) If Not Force Then If Forms.Count > i Then Exit Sub End If End If Next i If Force Or (Forms.Count = 0) Then Close If Force Or (Forms.Count > 0) Then End End Sub Private Sub Form_Unload(cancel As Integer) '彻底卸载所有窗体并退出程序 Shutdown (True) End Sub
Hide
Cancel = True
End Sub
建议你贴源代码看看。
'一个窗体
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Me.Visible = False
Cancel = True
End Sub
你试试这个:Private Sub Form_Unload(Cancel As Integer)
On Error Resume Next Dim ws As Workspace
Dim db As Database
Dim rs As Recordset For Each ws In Workspaces
For Each db In ws.Databases
For Each rs In db.Recordsets
rs.Close
Set rs = Nothing
Next
db.Close
Set db = Nothing
Next
ws.Close
Set ws = Nothing
Next End Sub
着急ing…………
谁解决了马上给分!!
强行卸载可以
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
end
End Sub
'卸载所有窗体
Dim i As Long
On Error Resume Next
For i = Forms.Count - 1 To 0 Step -1
Unload Forms(i)
If Not Force Then
If Forms.Count > i Then
Exit Sub
End If
End If
Next i
If Force Or (Forms.Count = 0) Then Close
If Force Or (Forms.Count > 0) Then End
End Sub
Private Sub Form_Unload(cancel As Integer)
'彻底卸载所有窗体并退出程序
Shutdown (True)
End Sub