shutting down applications

  • 19 years ago

    i need to shut down MS Access while i run an app that uses the CompactDatabase method do to some maintainence. i can't seem to find anything about shutting down applications.

    even shutting the database down and leaving access open before reopening after the task is complete would be cool but i can't seem to figure it out at all! any help would be appreciated.

  • 19 years ago

    How are you running access? Have you just used the Shell command, or are you using the Access object model?

  • 19 years ago

    i assume it's the Object Model .... Access is always running in the background to power an application written in VBA and i need it shut down every once in a while to perform the optimizing.

    i have the optimizing code written and sitting in a module in another app but i need to call that app, shut access down, perform the DB maintainence and reopen the database again without the user having to do anything.

    anyway around this?

  • 19 years ago

    How are you launching Access? Can you please give us a bit of code.... ;-)

  • 19 years ago

    the database isn't 'launched' as such .... it's totally seperate. i just need to shut it down while this code is run and then have it started up again. it's like the kind of thing that MySQL does on webservers to keep database sizes down.

    this code should give you the idea of what i'm doing

    Public Declare Function GetTempPath Lib "kernel32" Alias _
       "GetTempPathA" (ByVal nBufferLength As Long, ByVal lpBuffer _
       As String) As Long

    Public Const MAX_PATH = 260

    Public Sub CompactJetDatabase(Location As String)

    Dim MasterFile As String
    Dim strBackupFile As String
    Dim strTempFile As String

    ' need to shut down db here

    MasterFile = Location & "\fms.mdb"

    'Check the database exists
    If Dir$(MasterFile) = "fms.mdb" Then

       ' Create temporary filename
       strTempFile = Location & "\" & "fms_temp.mdb"
       If Dir$(strTempFile) Then Kill strTempFile

       ' Do the compacting via DBEngine
       DBEngine.CompactDatabase strTempFile, OptimDb

       ' add in code to copy OptinDB back to original here
       MsgBox ("Database is optimised! at last!")

       'need to restart db here


       MsgBox ("blah blah error! we're all going to die!")

    End If

    End Sub

  • 19 years ago

    Well... if you are using the Access object model (ie gone to Project|References and selected Microsoft Access) for VBA properties to be exposed, there is an Application.Quit method. So you could just call that before running your compact event....

Post a reply

Enter your message below

Sign in or Join us (it's free).


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“In theory, theory and practice are the same. In practice, they're not.”