naive has asked for the wisdom of the Perl Monks concerning the following question:

Hi,I am new to perl.Recently I have successfully open my files(extension .csv) from perl in MS Excel and MS Word using the source code below. Why can't I do the same for MS Access?Do I have to change the extension for my data_in file(which is in .csv to .mdb) before I can open the file in Access??If so,how am I suppose to go about doing it?? Below is the programme for opening in Excel(successful) and Access(unsuccessful),any help will be greatly appreciated!!! THks!!!


###########################
# For Excel #
# (successful) #
###########################

use Win32::OLE qw(in with);
use Win32::OLE::Const 'Microsoft Excel';

my $excelfile = 'c:\\Perl\\code\\data_in.csv';

my $Excel = Win32::OLE->GetActiveObject('Excel.Application') || Win32::OLE->new('Excel.Application', 'Quit');

my $Book = $Excel->Workbooks->Open($excelfile);

$Book->SaveAs( 'c:\\Perl\\code\\data_out.csv');


###################################
# For Access #
# (unsuccessful) #
###################################

use Win32::OLE qw(in with);
use Win32::OLE::Const 'Microsoft Access';

my $accessfile = 'c:\\Perl\\code\\data_in.csv';

my $Access = Win32::OLE->GetActiveObject('Access.Application') || Win32::OLE->new('Access.Application', 'Quit');

my $Book = $Access->Tables->Open($accessfile);

$Book->SaveAs( 'c:\\Perl\\code\\data_out.mdb' );

Replies are listed 'Best First'.
Re: MS Access & WIn32::OLE
by screamingeagle (Curate) on Jan 29, 2002 at 07:09 UTC
    Just by changing the extension of a file from .csv to .mdb wont help you , since Access will most likely complain that the file is not a valid MDB file...you'll need to dynamically import the csv file into an exising access database... if u have access to Access type library, the look for methods which will simulate importing data dynamically... hope this helps...

    Update : if u have Access installed, go to
    File->Get External Data->Import, to get a clearer idea of what u need to simulate dynamically.
Re: MS Access & WIn32::OLE
by simon.proctor (Vicar) on Jan 31, 2002 at 23:06 UTC