Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Closing an Access object that was started in Excel???

Status
Not open for further replies.

Apollo6

Technical User
Jan 27, 2000
418
US
First, what I want to do is open a specific access database from Excel, enter some records, close the Access application completely, and continue with Excel.

All is working fine but when I exit the database, the Access application does not quit until I close the Excel application that created it.

In my module, I have the following code:

Option Explicit
Public obj_Access As Object


Sub Add_Web_Reports()

Set obj_Access = CreateObject("Access.Application")

obj_Access.OpenCurrentDatabase ("C:\Some_database.mdb")

End Sub


Now, the reason I declared the object as Public is because I have three different procedures that call the same database, including the above procedure. The difference between them is that the other two open the database, run a macro, then close the database. These work fine and the access object is set to nothing and goes away.

In the above procedure, I need the user to be able to open the database, do some work, then exit. If I set obj_Access to Nothing, when the user clicks the menu option in Excel to open the database, it opens then closes immediately.

I understand why it is doing what it's doing, I just don't know how else to go about what I want to do. It is not a big deal, it just seems messy to have the Access object still live when the user is actually finished with Access.

Thanks in advance for any suggestions.
 
Apollo6,

You may already be doing this, but are using the 'quit' method?

for example:

obj_Access.Application.Quit ' or sometimes just obj_Access.Quit
set obj_Access = Nothing

It seems to work (xl97).

HTH MM
 
mmandk9:

I'm not having any trouble killing Access in the above procedure, but again, if I use app.quit or set the object to Nothing, the instance of Access automatically closes right after it has been opened.

Not setting it to Nothing or using App.Quit allows the instance to remain open. It's just that the instance will only go away when the instance of Excel is closed that created the instance of Access... The user may have other things to run in Excel before closing out of Excel. This basically leaves a session of Access open. The only way I can make it go away is to kill it through Task Manager...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top