Here's are a couple of scripts I had hanging around.  The first uses OLE the
second uses Win32::ODBC to do the job.

--
  Simon Oliver

use warnings;
use strict;
use Win32::OLE;

my $file="c:/test.mdb";

die "File '$file' already exists!\n" if (-e $file);

my $access = Win32::OLE->new('Access.Application');
$access->NewCurrentDatabase($file);
$access->Quit();

print -e $file ? "Ok" : "Error";



use warnings;
use strict;
use Win32::ODBC;

my $option = ODBC_ADD_SYS_DSN;
my $driver = 'Microsoft Access Driver (*.mdb)';
my $dsn = 'Test_DSN';
my $dbf = 'd:\temp\test.mdb';

my $conn = new Win32::ODBC()
  or print "Error creating ODBC object";

Win32::ODBC::ConfigDSN ( $option, $driver, 'DSN=$dsn', 'CREAT_DB=$dbf' ) 
  or print "Error creating DSN '$dsn'.\n";

print Win32::ODBC::Error();

$conn = new Win32::ODBC($dsn) 
  or print "Error opening DSN '$dsn'.\n";

print Win32::ODBC::Error();

my $sql = 'CREATE TABLE test_table (id int, name varchar(32))';

my $rv = $conn->Sql($sql);
warn $rv;

my @tables = $conn->TableList('','','','');

print join(',', @tables), "\n";

$conn->Close;

Reply via email to