469,953 Members | 2,327 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,953 developers. It's quick & easy.

Cannot close Access programatically

(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?

Nov 21 '05 #1
3 2333
Hi,

Marshal.ReleaseComObject(appAcc)
GC.Collect

Ken
--------------------------
"Rob Hughes" wrote:
(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?

Nov 21 '05 #2
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.
"Ken Tucker [MVP]" <Ke**********@discussions.microsoft.com> wrote in message
news:F7**********************************@microsof t.com...
Hi,

Marshal.ReleaseComObject(appAcc)
GC.Collect

Ken
--------------------------
"Rob Hughes" wrote:
(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?

Nov 21 '05 #3
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
--------------------
"Rob Hughes" <ro*******@aaidataTHIS.com> wrote in message
news:uF**************@tk2msftngp13.phx.gbl...
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.
"Ken Tucker [MVP]" <Ke**********@discussions.microsoft.com> wrote in message
news:F7**********************************@microsof t.com...
Hi,

Marshal.ReleaseComObject(appAcc)
GC.Collect

Ken
--------------------------
"Rob Hughes" wrote:
(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?


Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by salih ataoz | last post: by
2 posts views Thread by Antonio Dias | last post: by
1 post views Thread by Robert Waggoner | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.