use strict; use warnings; use Win32::OLE; use Win32::OLE::Const 'Microsoft Access'; # Change a standard file path to DOS. sub dos_path { local $_ = shift; tr{/}{\\}; return $_; } my $file = 'c:/file.mdb'; my $mdb = dos_path($file); # Use existing instance if Access is already running my $Access; eval { $Access = Win32::OLE->GetActiveObject('Access.Application') }; die "Access not installed" if $@; if ( not defined $Access ) { $Access = Win32::OLE->new( 'Access.Application', # sub { $_[0]->Quit }, # Optional destructor ) or die "Oops, cannot start Access"; } $Access->{'Visible'} = 1 if $Access->{'Visible'} != 1; if ( my $cur = $Access->CurrentDb ) { my $name = $cur->{'Name'}; if ($name ne $mdb) { my $rc = $Access->CloseCurrentDatabase(); print "\nClosing '$name', rc=$rc\n"; $Access->OpenCurrentDatabase($mdb); } else { print "\nDB already loaded\n"; } } else { $Access->OpenCurrentDatabase($mdb); print "Fresh open\n"; } # XXX *Something* must be opened at this point, # or the database will close when the Perl program ends. my $query_name = 'QArrangersComSummary'; $Access->DoCmd->OpenQuery( $query_name, acViewDesign, acReadOnly, );