質問

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