note 73229 modified in ref.com by danbrown
| From: | danbrown@php.net | Date: | Mon, 21 Dec 2009 17:04:19 +0000 |
| Subject: | note 73229 modified in ref.com by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-164196@lists.php.net to get a copy of this message | ||
I had the problem when trying to call Access VBA scripts from PHP; the call was working but Access
would never quit. The problem was that the Apache server is running as SYSTEM, and not a user we
normally use to run Office. And as the first time a user runs Office, it asked the SYSTEM user to
enter its name and initials! ;-)
To correct this problem: Stop Apache, go to Services, Apache, Properties, "Log On" tab,
and check "Allow service to interact with desktop. Restart Apache, then open your office
application, in a page loaded by the Apache server, with a small PHP code like this, :
<?php
$app = new COM("Access.Application"); // or Word.Application or Excel.Application ...
$app->Visible = true; // so that we see the window on screen
?>
Put the name you want and quit the application. Now your Office application should terminate
correctly the next time you load it with a COM object in PHP. You can stop Apache uncheck the
"Allow service to interact with desktop", and restart Apache if you like. I don't
even require a Quit or anything to be sent to Access, it quits automatically when PHP terminates.
And for those who wish to know how I'm calling Access VBA scripts, instead of using ODBC or any
other way to send SQL requests, which does not seem to work to call VBA scripts, I open the database
as a COM object and it works fine:
<?php
$db_com = new COM("pathname of the file.mdb");
$result = $db_com->Application->Run("function_name", 'param1',
'param2', '...');
?>
--was--
As allan666 pointed out, your Office application may not terminate correctly, and leave processes in
the background, if a dialog box was opened by the application.
I had the problem when trying to call Access VBA scripts from PHP; the call was working but Access
would never quit. The problem was that the Apache server is running as SYSTEM, and not a user we
normally use to run Office. And as the first time a user runs Office, it asked the SYSTEM user to
enter its name and initials! ;-)
To correct this problem: Stop Apache, go to Services, Apache, Properties, "Log On" tab,
and check "Allow service to interact with desktop. Restart Apache, then open your office
application, in a page loaded by the Apache server, with a small PHP code like this, :
<?php
$app = new COM("Access.Application"); // or Word.Application or Excel.Application ...
$app->Visible = true; // so that we see the window on screen
?>
Put the name you want and quit the application. Now your Office application should terminate
correctly the next time you load it with a COM object in PHP. You can stop Apache uncheck the
"Allow service to interact with desktop", and restart Apache if you like. I don't
even require a Quit or anything to be sent to Access, it quits automatically when PHP terminates.
And for those who wish to know how I'm calling Access VBA scripts, instead of using ODBC or any
other way to send SQL requests, which does not seem to work to call VBA scripts, I open the database
as a COM object and it works fine:
<?php
$db_com = new COM("pathname of the file.mdb");
$result = $db_com->Application->Run("function_name", param1, param2 â¦);
?>
http://php.net/manual/en/ref.com.php