Results 1 to 11 of 11
  1. #1
    3 Star Lounger
    Join Date
    Feb 2004
    Location
    Burgas, Bulgaria
    Posts
    209
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Close database from another database (Access 2000)

    I have the following command to open a database from another database :
    Dim appAccess As Access.Application
    Set appAccess = CreateObject("Access.Application")
    appAccess.OpenCurrentDatabase "C:BEDBCrates.mdb"

    What is the command for closing the database again this database ?

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Close database from another database (Access 2000)

    If you want to close the database but keep the instance of Access open:

    appAccess.CloseCurrentDatabase

    If you want to close the database and the instance of Access:

    appAccess.Quit
    Set appAccess = Nothing

  3. #3
    3 Star Lounger
    Join Date
    Feb 2004
    Location
    Burgas, Bulgaria
    Posts
    209
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Close database from another database (Access 2000)

    Thank you for your suggestion.I cannot close the database and open it again since i get the error that the object has been disconnected .Actually i want to disocennct and open again but didnt get it :
    Dim appAccess As Access.Application
    Set appAccess = CreateObject("Access.Application")
    appAccess.OpenCurrentDatabase "C:BECrates.mdb"
    appAccess.CloseCurrentDatabase
    appAccess.OpenCurrentDatabase "C:BECrates.mdb"
    appAccess.Quit
    Set appAccess = Nothing
    Application.Quit

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Close database from another database (Access 2000)

    Why do you want to do this?

  5. #5
    Lounger
    Join Date
    Nov 2006
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Close database from another database (Access 2000)

    I want to close Front End program with event Form_Close()
    The code is:
    Private Sub Form_Close()
    CloseProgram
    End Sub

    Function CloseProgram()
    Dim appAccess As Access.Application
    Dim stDB As DAO.Database
    Set stDB = CurrentDb
    stDB.Close
    Application.Quit
    Set Application = Nothing
    appAccess.Quit
    Set appAccess = Nothing
    End Function
    It works good on close, however it gives me run time error 438 (object doesn't support this property or method) when I try to close Access by MS Access close button (Red Cross)
    I feel that I miss something

    Thank you
    Alex

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Close database from another database (Access 2000)

    The only thing you need is Application.Quit, the rest makes no sense. So use

    Function CloseProgram()
    Application.Quit
    End Function

  7. #7
    Lounger
    Join Date
    Nov 2006
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Close database from another database (Access 2000)

    Yes, I started from that, but it leaves an MS Access instance running after the program had been closed
    Thank you

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Close database from another database (Access 2000)

    Without seeing the other code in your database, it's hard to say whether it is this particular code that causes an instance of Access to remain in memory.

    I would not use the Form_Close event to quit the application, but place a command button on the form that executes Application.Quit when clicked.

  9. #9
    Lounger
    Join Date
    Nov 2006
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Close database from another database (Access 2000)

    I'd like to close program when user wants to close the Form by form_close "X" button
    and it still leave instance of Access all the time if I use "application.quit " statement
    the code I provided earlier has fixed that problem, however I was getting an error message right before the closing
    thank you very much

  10. #10
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Close database from another database (Access 2000)

    I'm afraid I don't understand how your code could fix the problem - it makes no sense to me.

    But anyway, you can disable the close button in the upper right corner of the Access window.
    - Copy the code from the attached text file into a module.
    - Execute the following instruction when the database is opened, for example in the On Open event of the startup form or of the form with your Form_Close code.

    SetCloseBox False

    The "x" in the upper right corner of the Access window will be disabled, but Application.Quit will still work.

  11. #11
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Re: Close database from another database (Access 2000)

    Use the following instead of Application.Quit:
    <pre>Function CloseProgram()
    DoCmd.Quit ' Allows Compact on close and gets rid of the Access instance as well
    End Function
    </pre>


Posting Permissions

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