Cannot close Access programatically

R

Rob Hughes

(This is a crosspost from .data for greater exposure)

I am writing an external app that utilizes. The app needs to be able to run
repeatedly, but I am having a problem because Access will not close. When
..Quit is called, it pops up a blank Access window, which will not close by
normal means, only by ending the process in Task Manager. Oddly enough, the
first time that this is run after a reboot, it works fine, but every time
after that, it will not close.

Here is the applicable Access code, in VB.NET:

Dim appAcc As New Access.Application
appAcc.Visible = False
appAcc.OpenCurrentDatabase(dbname, True)
appAcc.DoCmd.DeleteObject(acTable, "ArcSumm")
appAcc.DoCmd.DeleteObject(acTable, "zip_table")
appAcc.DoCmd.DeleteObject(acTable, "ArcCover")
appAcc.DoCmd.TransferDatabase(acImport, "dBase 5.0", dbloc + pnum, acTable,
"ArcSumm", "ArcSumm")
appAcc.DoCmd.TransferDatabase(acImport, "dBase 5.0", dbloc + pnum, acTable,
"ArcCover", "ArcCover")
appAcc.DoCmd.TransferDatabase(acImport, "dBase 5.0", dbloc + pnum, acTable,
"ArcZips", "zip_table")
appAcc.DoCmd.RunMacro("webCover")
Dim summ As DAO.Recordset
summ = appAcc.CurrentDb.OpenRecordset("ArcSumm")
If summ.RecordCount = 0 Then
appAcc.DoCmd.RunMacro("DoEverythingWebNoHaz")
Else
appAcc.DoCmd.RunMacro("DoEverythingWeb")
End If
summ.Close()
summ = Nothing
appAcc.DoCmd.OpenReport("Definitions", Access.AcView.acViewNormal) 'dummy
report to flush the pdf file
appAcc.DoCmd.Close(acReport, "Definitions", Access.AcCloseSave.acSaveNo)
appAcc.CloseCurrentDatabase()
appAcc.Quit(Access.AcQuitOption.acQuitSaveNone)
appAcc = Nothing

I have tried to ensure that everything is closed out, and yet it persist in
popping up the Access window. If I try to run the app again, it fails
because it cannot access the database.

Can anyone advise me what to do?
 
R

Rob Hughes

Excellent, thank you.

As a learning .NET programmer, I'm still picking up on certain practices. Is
it a good idea to finish off all programs with a GC.Collect? That was one of
the things that I just assumed it did automatically.
 
K

Ken Tucker [MVP]

Hi,

You dont have to. When you use marshal.releasecomobject the
object is freed the next time the garbage collector collects the garbage.
This will happen automatically but I wanted to run right away and release
access.

Ken
--------------------
Excellent, thank you.

As a learning .NET programmer, I'm still picking up on certain practices. Is
it a good idea to finish off all programs with a GC.Collect? That was one of
the things that I just assumed it did automatically.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top