Disconnect all data connections

xiaoxiao2021-03-06  15

If data controls such as DAO, RDO, or ADO are used in the code, all open Recordset, Database, and Workspace should be turned off when exiting. Although the object can be logged out, the data connection will not be disconnected immediately, and some memory cannot be reassigned by the system.

The following code can close all open DAO Workspace, and release the memory.

Private Sub Form_Unload (Cancel AS Integer)

ON Error ResMe 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

转载请注明原文地址:https://www.9cbs.com/read-49544.html

New Post(0)