---- 下面有一段放在Form_Unload 事件(或者其他退出模塊中)中的一小段代碼例子,它演示了關閉所有打開的DAO 工作臺、數據庫和記錄并釋放了被這些對象占用的內存。當你退出FORM時,不論在有一個、100個甚至沒有數據庫連接時都可以使用下面代碼。
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
延伸閱讀
文章來源于領測軟件測試網 http://www.kjueaiud.com/