FYI, here are the first two lines from site/lib/OLE.pm:

# Compatibility layer for applications using the old toplevel OLE.pm. # New code should use Win32::OLE

The code below is very suspect. I wrote it in 2004 as part of a hurried (and failed) effort to dump all the details of the Query and Report objects from an Access database. The program was never completed or documented, and I don't recall any of the reasoning behind its peculiarities, such as why not to set Visible if Visible is already set. Hopefully it will be enough to solve your problem.

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, );

Finally, I am adding the code below, which uses the command-line method you said you did not want, just in case you eschewed the simpler method from some false pre-conceived idea.

use strict; use warnings; use Win32::TieRegistry( Delimiter=>'/', ArrayValues=>0 ); my $mdb = 'c:/file.mdb'; sub find_MSAccess { my $key = 'HKEY_CLASSES_ROOT/Applications/MSACCESS.EXE/shell/Open/co +mmand//'; my $pgm = $Registry->{$key} or die; # $pgm looks like '"C:\Program Files\Microsoft Office\OFFICE11\MSACC +ESS.EXE" /NOSTARTUP "%1"' $pgm =~ s{ \A " ( .*? MSACCESS\.EXE ) " .* \z }{$1}xi or die; return $pgm; } # Change a standard file path to DOS. sub dos_path { local $_ = shift; tr{/}{\\}; return $_; } my $access_pgm = find_MSAccess(); die "Can't run '$access_pgm'" unless -x $access_pgm; my @cmd = ( 'start', $access_pgm, dos_path($mdb), ); system(@cmd)==0 or die "System command failed!\nCommand was: '@cmd'\nError was: '$@' +\n ";


In reply to Re: How to display an Access database by Util
in thread How to display an Access database by jobs_ron

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.