Вопрос

I am new to perl. I am asked to execute a macro in ms access database using perl. This is the code i used

$oAccess = Win32::OLE->GetActiveObject('Access.Application');  
$oAccess ->OpenCurrentDatabase($path);  
$oAccess ->{DoCmd}->RunMacro("DO ALL");  

Today when i was executing the program i found that only if the access database is open the code works fine else it returns the following error

Can't call method "OpenCurrentDatabase" on an undefined value at auto.pl line 30  

So I was wondering if i could find any other code which would serve the purpose without an open ms access database.

Это было полезно?

Решение

my $MSAccess;
eval {$MSAccess = Win32::OLE->GetActiveObject('Access.Application')};
die "Access not installed" if $@;
unless (defined $MSAccess) {
  $MSAccess = Win32::OLE->new('Access.Application','Quit')
    or die "Unable to start Access";
}
$MSAccess->{visible} = 0;
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top