views:

192

answers:

2

Dear All,

Is there a way in by sql statement or vba code to return all tables from access file? "I don't know the name of the tables"

like when you want to have all fields in a table you use '*' regardless the names of the fields.

but how to get all tables?!!!!

A: 

Depends what kind of database you are running. Many of them support the SHOW TABLES command.

Adam Pierce
it's access database
amr osama
-1 for shooting without aiming -- the MS-ACCESS tag was on the question as originally posted.
David-W-Fenton
+2  A: 

This will bring back all tables in the MS Access database (including linked tables)

SELECT MSysObjects.*, MSysObjects.Type
FROM MSysObjects
WHERE (((MSysObjects.Type)=1)) OR (((MSysObjects.Type)=6));

It also inclued Sys tables, so you might want to exclude tables starting with MSys

Have a look at

astander
thanks a lot I got this from your answer ->SELECT MSysObjects.NameFROM MSysObjectswhere (MSysObjects.Name) Not Like "Msys*" andMSysObjects.Name not like "Tables" andMSysObjects.Name not like "Databases" andMSysObjects.Name not like "Relationships" andMSysObjects.Name not like "SummaryInfo" andMSysObjects.Name not like "UserDefined" andMSysObjects.Name not like "Forms" andMSysObjects.Name not like "Reports" andMSysObjects.Name not like "Scripts" andMSysObjects.Name not like "Modules" andMSysObjects.Name not like "SysRel" andMSysObjects.Name not like "DataAccessPages" and it work
amr osama
You know this is really great but my problem didn't solve it yet :(, what I want is when my dataSource opened I have all tables inserted automatically in the microsoft query -Query form, any hints to that?
amr osama
Where do you wish to use this result, in a list box, on a form, in another query, as a Record Source?
astander
in Excel go to data menu-> pivot table .......... -> external data source -> press next -> press on get data button -> in the choose data source dialog, pick your data source from the list then press okay-> the Microsoft Query opens now and open query design, and have default table inserted in this board, here I want to have all tables which might be in the database not just the default table and this should be automatically, without any action from the user after Microsoft Query opens, that's it
amr osama
OOops, I think I am missing something here, by this I query on MSysObjects table not on all of my tables, I will think again
amr osama