Avatar of TommyTupa
TommyTupa

asked on 

Why run this vba on exit?

I am loooking at someone elses MS Access application that runs the code below on exiting.  What purpose does it serve?  Why not just do application.quit?


Public Function ExitDatabase() As Boolean

    CloseObject "Tables", A_TABLE
    CloseObject "Tables", A_QUERY
    CloseObject "Forms", A_FORM
    CloseObject "Reports", A_REPORT
    CloseObject "Scripts", A_MACRO
    CloseObject "Modules", A_MODULE
       
    DoCmd.Quit

End Function



Private Sub CloseObject(sName As String, iType As Integer)

    Dim db          As Database
    Dim cntCurrent  As Container
    Dim i  As Integer

    Set db = DBEngine.Workspaces(0).Databases(0)
    Set cntCurrent = db.Containers(sName)

    For i = 0 To cntCurrent.Documents.Count - 1
        DoCmd.Close iType, cntCurrent.Documents(i).Name
    Next i

End Sub
Microsoft Access

Avatar of undefined
Last Comment
TommyTupa

8/22/2022 - Mon