sub getTableDefs
{
$accessConst = Win32::OLE::Const->Load('Microsoft Access 8.0 O
+bject Library');
$daoConst = Win32::OLE::Const->Load('Microsoft DAO 3.51 Object
+Library');
#array to hold table names
my @names;
#Create a new OLE Access.Application object
my $app = Win32::OLE->new('Access.Application');
#Open the database being worked in
$app->OpenCurrentDatabase($datasource);
#Get the database object
my $database = $app->CurrentDb();
#Save every table name that is not a system or linked table
foreach my $i (0..($database->TableDefs->{Count}-1))
{
#If the attributes are 0 (ie a normal table)
if(!$database->TableDefs($i)->{Attributes} || $database->Table
+Defs($i)->{Attributes} eq $daoConst->{'dbAttachedTable'})
{
#add it to the list of valid selections
push @names $database->TableDefs($i)->{Name};
}
}
#Quit the application
$app->DoCmd->Quit($accessConst->{'acQuitSaveNone'});
#Return the list of valid table names
return @names;
}
This is some code I wrote a while ago. It does work but it might not be exactly what you want. It only counts non system tables and non-linked tables. this was in a package.. I moved the constant object declaration into the sub for clarity when I pasted it here.
Again.. this code has been tested and does work. I hope this can be of some use to you.
P.S. If you open up the object browser in access, and you can check what the possible values of the attribute method are, so you can know which table you want to count. There is also a QueryDef collection if you are interested in counting those.
Grygonos
|