http://qs1969.pair.com?node_id=474201


in reply to exporting MS ACCESS tables into a CSV file

This is a simple example for a table Clients with fields CompanyName, ClientID, Phone in a file TestAccess.mdb.
See also Text::CSV.
use strict; use Win32::OLE; use Win32::OLE::Const 'Microsoft ActiveX Data Objects'; # Change these three variables my $database = "TestAccess.mdb"; my $table = "Clients"; my $field1 = "CompanyName"; my $field2 = "ClientID"; my $field3 = "Phone"; my $Conn = Win32::OLE->new("ADODB.Connection"); my $RS = Win32::OLE->new("ADODB.Recordset"); my $DSN = "PROVIDER=MSDASQL;DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=$database;UID=;PWD=;"; $Conn->Open($DSN); my $SQL = "SELECT $field1, $field2, $field3 FROM $table"; $RS->Open($SQL, $Conn, 1, 1); until ($RS->EOF) { my $value1 = $RS->Fields($field1)->value; my $value2 = $RS->Fields($field2)->value; my $value3 = $RS->Fields($field3)->value; print $value1,"\t",$value2,"\t",$value3,"\n"; $RS->MoveNext; } $RS->Close; $Conn->Close;

Replies are listed 'Best First'.
Re^2: exporting MS ACCESS tables into a CSV file
by chicago928 (Initiate) on Jul 12, 2005 at 08:32 UTC
    what if i don't know the table names or the fields in each table in advance? I will however easily know the filenames.
Re^2: exporting MS ACCESS tables into a CSV file
by Anonymous Monk on Apr 08, 2008 at 10:40 UTC
    Hi All, I have tries the above code but when i'm trying to access the tables and columns which contains white spaces it's giving the following error: (Can't call method "value" on an undefined value) Please help