Hi,
I'm working in Windows Vista, using ActivePerl 5.8.7 Build 813, using MS Access 2007, and executing the .pl file in MKS KornShell.
I'm trying to use Win32:OLE to open an existing MS Access .mdb file and run a public subroutine:
Most of my searches have yielded very little on this; the examples I have found primary focus on Excel and Word. The examples with Access focus primarily on using DBI to query data to/from the Access database.
Following are two pieces of code I've pieced together from what I've been able to find. Neither of them work and I'm unable to figure out what is incorrect.
Attempt #1:
Attempt #2:
Any help or examples would be greatly appreciated.
Thanks!
- Bruce
I'm working in Windows Vista, using ActivePerl 5.8.7 Build 813, using MS Access 2007, and executing the .pl file in MKS KornShell.
I'm trying to use Win32:OLE to open an existing MS Access .mdb file and run a public subroutine:
Most of my searches have yielded very little on this; the examples I have found primary focus on Excel and Word. The examples with Access focus primarily on using DBI to query data to/from the Access database.
Following are two pieces of code I've pieced together from what I've been able to find. Neither of them work and I'm unable to figure out what is incorrect.
Attempt #1:
Code:
#!/usr/bin/perl
use strict;
use warnings;
use Win32::OLE::Const 'Microsoft Access';
my $Filename = "s:/mdbtest.mdb";
my $loAccess; # Access Object
my $loDatabase; # Database Object
eval {$loAccess = Win32::OLE->GetActiveObject('Access.Application')};
die "Access not installed" if $@;
unless (defined $loAccess) {
$loAccess = Win32::OLE->new('Access.Application','Quit')
or die "Unable to start Access";
}
$loDatabase = $loAccess->DBEngine->OpenDatabase($Filename);
if (Win32::OLE->LastError) {
print "Unable to Open Access Database, LastError returned ",
Win32::OLE->LastError, "\n";
}
Attempt #2:
Code:
#!/usr/bin/perl
use strict;
use warnings;
use Win32::OLE::Const 'Microsoft Access';
my $Filename = "s:/dev/devbatch/bruce/mdbtest.mdb";
#my $Access = Win32::OLE->new('Access.Application', 'Quit');
#my $Access = Win32::OLE->getActiveObject('Access.Application');
my $Access = Win32::OLE->GetObject($Filename);
my $Workspace = $Access->DBEngine->CreateWorkspace('', 'Admin', '');
$Access -> OpenCurrentDatabase($Filename);
$Access->{'Visible'}=1;
$Access->RunTest();
#$Access -> DoCmd -> RunMacro("RunTest");
##$Access -> Quit();
Any help or examples would be greatly appreciated.
Thanks!
- Bruce