in reply to How to List MS Access 2007 Modules with Perl

I recommend automating MS Access through Win32::OLE. That way, you'll get access to all the properties just like from VBA.

  • Comment on Re: How to List MS Access 2007 Modules with Perl

Replies are listed 'Best First'.
Re^2: How to List MS Access 2007 Modules with Perl
by Mundi (Initiate) on Mar 28, 2010 at 19:37 UTC

    Thanks

    Modules collection is part of "CurrentProject." here's the OLE connection I'm making:

    #!perl -w #-- code to access Ms Access objects use Win32::OLE qw(in with); use Win32::OLE::Const 'Microsoft DAO'; use Win32::OLE::Const 'Microsoft ActiveX Data Objects'; my $file = q{C:\\...\\Northwind 2007.accdb}; my $appAcc = Win32::OLE->new('Access.Application', 'Quit'); my $Workspace = $appAcc->DBEngine->CreateWorkspace('', 'Admin', ''); # $appAcc->OpenCurrentDatabase my $Database = $Workspace->OpenDatabase($file); # my $Database = $appAcc->OpenCurrentDatabase($file); if (!$Database) { print Win32::OLE->LastError(), "\n"; } else { print $Database->{Name}, "\n"; print $Database->{CurrentProject}->Modules(0)->{Name}, "\n"; }

    The last statement causes the error:

    OLE exception from "DAO.TableDefs": Item not found in this collection. Win32::OLE(0.1709) error 0x80020009: "Exception occurred" in METHOD/PROPERTYGET "CurrentProject" at getAccessOLE.pl line 27

      There is no CurrentProject (and no CurrentDatabase) as you found out. Maybe there is Projects or some other property that is independent of a concept of "current". Look through the MS Access documentation to find where all projects are listed, and then look through that collection.

      I'll keep on digging