Esta função é utilizada no evento Unload do seu formulário principal;
- Código:
Public Function EvitaCorrupcao()
'By jpaulo 03-01-2018 - www.maximoaccess.com
'Evita corrupção do banco
'Usar no evento Unload do seu form Principal
'Private Sub Form_Unload(Cancel As Integer)
' Call EvitaCorrupcao
'End Sub
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
On Error Resume Next
Application.Quit acQuitSaveAll
End Function