Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 251
  • Last Modified:

Problem with launching and closing MS Access from a web page with JavaScript using ActiveXObject() OLE Automation

I have an issue with a JavaScript function I am using within a PHP web page to launch MS Access and print a report.  The script works great accept that it leaves an MSACCESS.EXE process open on the client machine (running Windows XP Pro) which ties up about 20Mb of RAM.  The problem is compounded since every time the script is run it creates another instance of the process.  This script will be run on 3-4 workstations at 30-40 times each daily.  Having 30-40 instances of the process running is obviously a problem.  I'm looking for a statement I can include within the JavaScript that will close the MSACCESS.EXE process once it has finished, but still keep MS Access invisible.  Thank you all in advance for the assistance.  Below is a copy of the script I am using:

<script language="JavaScript">
      function JSAccess(DBASE, REPORT)
      {
            var AccessApp = new ActiveXObject("Access.Application");
            AccessApp.Visible = false;
            AccessApp.OpenCurrentDatabase(DBASE);
            AccessApp.DoCmd.OpenReport(REPORT);
      }
</script>
0
wthero
Asked:
wthero
  • 2
1 Solution
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
Here is some vba code I happen to be working on ... which from an MDB that I open with a shortcut does the following:

1) Copies another MDB to from folder abc to folder xys
2) Opens that MDB (AppOpenTest.mdb)
3) Closes this mdb

This leaves just one instance of Access open AppOpenTest
When the user closes AppOpenTest, the instance IS gone from memory.

Public Function mLaunchTestV2() As Boolean
     
    Dim o As Application
    Dim dbfname As String, dbName As String
    Dim mversion As String
    Dim dbffolder As String
    dbffolder = "C:\xyz"
    dbName = "AppOpenTest.mdb"
    FileCopy "\abc\AppOpenTest.mdb", "C:\xyz\AppOpenTest.mdb"
    Set o = CreateObject("Access.Application")
    ChDir dbffolder
    o.OpenCurrentDatabase (dbffolder & "\" & dbName)
    DoEvents
    o.UserControl = True    'important                *** This line my help you ???
    Set o = Nothing
    Application.Quit

End Function

mx
0
 
wtheroAuthor Commented:
Thank you MX.  It was the 'Application.Quit' command I was missing.  Once I appended my script with 'AccessApp.Application.Quit();' it worked wonderfully.  Here is my final working script:

<script language="JavaScript">
      function JSAccess(DBASE, REPORT)
      {
            var AccessApp = new ActiveXObject("Access.Application");
            AccessApp.Visible = false;
            AccessApp.OpenCurrentDatabase(DBASE);
            AccessApp.DoCmd.OpenReport(REPORT);
AccessApp.Application.Quit();
      }
</script>
0
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
Good timing ... I *just* happen to be working an App (mdb) Launcher program ... as of last night ... using basically that same code.

mx
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now