bdbmeag has asked for the wisdom of the Perl Monks concerning the following question:
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:#!/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"; }
Any help or examples would be greatly appreciated. Thanks! - Bruce#!/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();
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Use Win32::OLE to run vba subroutine in MS Access
by Corion (Patriarch) on Oct 05, 2008 at 21:39 UTC | |
|
Re: Use Win32::OLE to run vba subroutine in MS Access
by NetWallah (Canon) on Oct 05, 2008 at 22:51 UTC | |
by bdbmeag (Initiate) on Oct 06, 2008 at 21:01 UTC | |
by NetWallah (Canon) on Oct 07, 2008 at 05:28 UTC |