Cannot close Access programatically

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Rob Hughes

    #1

    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.Applicat ion
    appAcc.Visible = False
    appAcc.OpenCurr entDatabase(dbn ame, True)
    appAcc.DoCmd.De leteObject(acTa ble, "ArcSumm")
    appAcc.DoCmd.De leteObject(acTa ble, "zip_table" )
    appAcc.DoCmd.De leteObject(acTa ble, "ArcCover")
    appAcc.DoCmd.Tr ansferDatabase( acImport, "dBase 5.0", dbloc + pnum, acTable,
    "ArcSumm", "ArcSumm")
    appAcc.DoCmd.Tr ansferDatabase( acImport, "dBase 5.0", dbloc + pnum, acTable,
    "ArcCover", "ArcCover")
    appAcc.DoCmd.Tr ansferDatabase( acImport, "dBase 5.0", dbloc + pnum, acTable,
    "ArcZips", "zip_table" )
    appAcc.DoCmd.Ru nMacro("webCove r")
    Dim summ As DAO.Recordset
    summ = appAcc.CurrentD b.OpenRecordset ("ArcSumm")
    If summ.RecordCoun t = 0 Then
    appAcc.DoCmd.Ru nMacro("DoEvery thingWebNoHaz")
    Else
    appAcc.DoCmd.Ru nMacro("DoEvery thingWeb")
    End If
    summ.Close()
    summ = Nothing
    appAcc.DoCmd.Op enReport("Defin itions", Access.AcView.a cViewNormal) 'dummy
    report to flush the pdf file
    appAcc.DoCmd.Cl ose(acReport, "Definition s", Access.AcCloseS ave.acSaveNo)
    appAcc.CloseCur rentDatabase()
    appAcc.Quit(Acc ess.AcQuitOptio n.acQuitSaveNon e)
    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?



  • Ken Tucker [MVP]

    #2
    RE: Cannot close Access programatically

    Hi,

    Marshal.Release ComObject(appAc c)
    GC.Collect

    Ken
    --------------------------
    "Rob Hughes" wrote:
    [color=blue]
    > (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.Applicat ion
    > appAcc.Visible = False
    > appAcc.OpenCurr entDatabase(dbn ame, True)
    > appAcc.DoCmd.De leteObject(acTa ble, "ArcSumm")
    > appAcc.DoCmd.De leteObject(acTa ble, "zip_table" )
    > appAcc.DoCmd.De leteObject(acTa ble, "ArcCover")
    > appAcc.DoCmd.Tr ansferDatabase( acImport, "dBase 5.0", dbloc + pnum, acTable,
    > "ArcSumm", "ArcSumm")
    > appAcc.DoCmd.Tr ansferDatabase( acImport, "dBase 5.0", dbloc + pnum, acTable,
    > "ArcCover", "ArcCover")
    > appAcc.DoCmd.Tr ansferDatabase( acImport, "dBase 5.0", dbloc + pnum, acTable,
    > "ArcZips", "zip_table" )
    > appAcc.DoCmd.Ru nMacro("webCove r")
    > Dim summ As DAO.Recordset
    > summ = appAcc.CurrentD b.OpenRecordset ("ArcSumm")
    > If summ.RecordCoun t = 0 Then
    > appAcc.DoCmd.Ru nMacro("DoEvery thingWebNoHaz")
    > Else
    > appAcc.DoCmd.Ru nMacro("DoEvery thingWeb")
    > End If
    > summ.Close()
    > summ = Nothing
    > appAcc.DoCmd.Op enReport("Defin itions", Access.AcView.a cViewNormal) 'dummy
    > report to flush the pdf file
    > appAcc.DoCmd.Cl ose(acReport, "Definition s", Access.AcCloseS ave.acSaveNo)
    > appAcc.CloseCur rentDatabase()
    > appAcc.Quit(Acc ess.AcQuitOptio n.acQuitSaveNon e)
    > 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?
    >
    >
    >
    >[/color]

    Comment

    • Rob Hughes

      #3
      Re: Cannot close Access programatically

      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]" <KenTuckerMVP@d iscussions.micr osoft.com> wrote in message
      news:F71AEAF6-9A82-493A-AC0C-FA2224E9013B@mi crosoft.com...[color=blue]
      > Hi,
      >
      > Marshal.Release ComObject(appAc c)
      > GC.Collect
      >
      > Ken
      > --------------------------
      > "Rob Hughes" wrote:
      >[color=green]
      > > (This is a crosspost from .data for greater exposure)
      > >
      > > I am writing an external app that utilizes. The app needs to be able to[/color][/color]
      run[color=blue][color=green]
      > > repeatedly, but I am having a problem because Access will not close.[/color][/color]
      When[color=blue][color=green]
      > > ..Quit is called, it pops up a blank Access window, which will not close[/color][/color]
      by[color=blue][color=green]
      > > normal means, only by ending the process in Task Manager. Oddly enough,[/color][/color]
      the[color=blue][color=green]
      > > first time that this is run after a reboot, it works fine, but every[/color][/color]
      time[color=blue][color=green]
      > > after that, it will not close.
      > >
      > > Here is the applicable Access code, in VB.NET:
      > >
      > > Dim appAcc As New Access.Applicat ion
      > > appAcc.Visible = False
      > > appAcc.OpenCurr entDatabase(dbn ame, True)
      > > appAcc.DoCmd.De leteObject(acTa ble, "ArcSumm")
      > > appAcc.DoCmd.De leteObject(acTa ble, "zip_table" )
      > > appAcc.DoCmd.De leteObject(acTa ble, "ArcCover")
      > > appAcc.DoCmd.Tr ansferDatabase( acImport, "dBase 5.0", dbloc + pnum,[/color][/color]
      acTable,[color=blue][color=green]
      > > "ArcSumm", "ArcSumm")
      > > appAcc.DoCmd.Tr ansferDatabase( acImport, "dBase 5.0", dbloc + pnum,[/color][/color]
      acTable,[color=blue][color=green]
      > > "ArcCover", "ArcCover")
      > > appAcc.DoCmd.Tr ansferDatabase( acImport, "dBase 5.0", dbloc + pnum,[/color][/color]
      acTable,[color=blue][color=green]
      > > "ArcZips", "zip_table" )
      > > appAcc.DoCmd.Ru nMacro("webCove r")
      > > Dim summ As DAO.Recordset
      > > summ = appAcc.CurrentD b.OpenRecordset ("ArcSumm")
      > > If summ.RecordCoun t = 0 Then
      > > appAcc.DoCmd.Ru nMacro("DoEvery thingWebNoHaz")
      > > Else
      > > appAcc.DoCmd.Ru nMacro("DoEvery thingWeb")
      > > End If
      > > summ.Close()
      > > summ = Nothing
      > > appAcc.DoCmd.Op enReport("Defin itions", Access.AcView.a cViewNormal)[/color][/color]
      'dummy[color=blue][color=green]
      > > report to flush the pdf file
      > > appAcc.DoCmd.Cl ose(acReport, "Definition s", Access.AcCloseS ave.acSaveNo)
      > > appAcc.CloseCur rentDatabase()
      > > appAcc.Quit(Acc ess.AcQuitOptio n.acQuitSaveNon e)
      > > appAcc = Nothing
      > >
      > > I have tried to ensure that everything is closed out, and yet it persist[/color][/color]
      in[color=blue][color=green]
      > > 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?
      > >
      > >
      > >
      > >[/color][/color]


      Comment

      • Ken Tucker [MVP]

        #4
        Re: Cannot close Access programatically

        Hi,

        You dont have to. When you use marshal.release comobject 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" <robDELETE@aaid ataTHIS.com> wrote in message
        news:uFhiqTbdFH A.1036@tk2msftn gp13.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]" <KenTuckerMVP@d iscussions.micr osoft.com> wrote in message
        news:F71AEAF6-9A82-493A-AC0C-FA2224E9013B@mi crosoft.com...[color=blue]
        > Hi,
        >
        > Marshal.Release ComObject(appAc c)
        > GC.Collect
        >
        > Ken
        > --------------------------
        > "Rob Hughes" wrote:
        >[color=green]
        > > (This is a crosspost from .data for greater exposure)
        > >
        > > I am writing an external app that utilizes. The app needs to be able to[/color][/color]
        run[color=blue][color=green]
        > > repeatedly, but I am having a problem because Access will not close.[/color][/color]
        When[color=blue][color=green]
        > > ..Quit is called, it pops up a blank Access window, which will not close[/color][/color]
        by[color=blue][color=green]
        > > normal means, only by ending the process in Task Manager. Oddly enough,[/color][/color]
        the[color=blue][color=green]
        > > first time that this is run after a reboot, it works fine, but every[/color][/color]
        time[color=blue][color=green]
        > > after that, it will not close.
        > >
        > > Here is the applicable Access code, in VB.NET:
        > >
        > > Dim appAcc As New Access.Applicat ion
        > > appAcc.Visible = False
        > > appAcc.OpenCurr entDatabase(dbn ame, True)
        > > appAcc.DoCmd.De leteObject(acTa ble, "ArcSumm")
        > > appAcc.DoCmd.De leteObject(acTa ble, "zip_table" )
        > > appAcc.DoCmd.De leteObject(acTa ble, "ArcCover")
        > > appAcc.DoCmd.Tr ansferDatabase( acImport, "dBase 5.0", dbloc + pnum,[/color][/color]
        acTable,[color=blue][color=green]
        > > "ArcSumm", "ArcSumm")
        > > appAcc.DoCmd.Tr ansferDatabase( acImport, "dBase 5.0", dbloc + pnum,[/color][/color]
        acTable,[color=blue][color=green]
        > > "ArcCover", "ArcCover")
        > > appAcc.DoCmd.Tr ansferDatabase( acImport, "dBase 5.0", dbloc + pnum,[/color][/color]
        acTable,[color=blue][color=green]
        > > "ArcZips", "zip_table" )
        > > appAcc.DoCmd.Ru nMacro("webCove r")
        > > Dim summ As DAO.Recordset
        > > summ = appAcc.CurrentD b.OpenRecordset ("ArcSumm")
        > > If summ.RecordCoun t = 0 Then
        > > appAcc.DoCmd.Ru nMacro("DoEvery thingWebNoHaz")
        > > Else
        > > appAcc.DoCmd.Ru nMacro("DoEvery thingWeb")
        > > End If
        > > summ.Close()
        > > summ = Nothing
        > > appAcc.DoCmd.Op enReport("Defin itions", Access.AcView.a cViewNormal)[/color][/color]
        'dummy[color=blue][color=green]
        > > report to flush the pdf file
        > > appAcc.DoCmd.Cl ose(acReport, "Definition s", Access.AcCloseS ave.acSaveNo)
        > > appAcc.CloseCur rentDatabase()
        > > appAcc.Quit(Acc ess.AcQuitOptio n.acQuitSaveNon e)
        > > appAcc = Nothing
        > >
        > > I have tried to ensure that everything is closed out, and yet it persist[/color][/color]
        in[color=blue][color=green]
        > > 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?
        > >
        > >
        > >
        > >[/color][/color]



        Comment

        Working...