Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2009
    Location
    Antwerp (Belgium)
    Posts
    33

    Unanswered: How to Close Access 2007 in "terminal error"

    I have this

    Option Compare Database
    Option Explicit

    Sub test()
    Dim o As Class1
    Set o = New Class1
    Application.CloseCurrentDatabase
    End Sub
    in a module and this ...

    Option Compare Database
    Option Explicit

    Private Sub Class_Initialize()
    End Sub

    Private Sub Class_Terminate()
    MsgBox "coucou"
    End Sub
    in a class module.

    When I run "test", the terminate of my class is not triggered. I've tried with docmd.quit to no avail. You would expect this to happen no? as variable o goes out of scope?

    Is there no "automatic" way to trigger "terminate" methods of open classes when you "quit". Anybody seen a way of doing that?

    I would have liked to cleanup temporary files and more importantly, rollback before the system closes down in case of terminal errors.

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Instead of using a class module, create a form:
    In the class module of Form1:
    Code:
    Option Compare Database
    Option Explicit
    
    Private Sub Form_Close()
    
        MsgBox "Closing"
        
    End Sub
    In Module1:
    Code:
    Option Compare Database
    Option Explicit
    
    Sub test()
    
        DoCmd.OpenForm "Form1", , , , , acHidden
        Application.CloseCurrentDatabase
        
    End Sub
    Now it works.
    Have a nice day!

  3. #3
    Join Date
    Dec 2009
    Location
    Antwerp (Belgium)
    Posts
    33

    It's an idea indeed.

    Weird, but doable in certain circumstances.
    Thanks.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •