Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

If a certain table exists 1

Status
Not open for further replies.

awhitsel

Programmer
Feb 22, 2001
80
US
I would like to know if there is any way to determine if a certain table exists in a database.

I am writing an data viewer application, and one of the screens is dependent on a table existing in the system.

If the table exists in the system, open up the form. Otherwise, run a series of queries to re-establish the needed table, populate it with data, and then opne up the form.

Any suggestions?
 
Check into the help files for tableDefs collection and TableDef object. You should be able to loop throught he tableDefs collection and test the name to see whether or not the table exists.

Another option would be to try a simple SQL command on the table and trap for the error that comes back if the table isn't there. Not very elegant, in that you're relying on an error to branch your code, but if there are a lot of tables in your database it might be faster this way.

Jeremy =============
Jeremy Wallace
Designing, Developing, and Deploying Access Databases Since 1995

Take a look at the Developer's section of the site for some helpful fundamentals.
 
Hi

SELECT Name FROM MSysObjects WHERE Type = 6 and Name = 'MyTableName';

Should do it I think, if no rows returned table is not there, otherwise it is Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
UK
 
Duh! No surprise that Ken comes up with the better solution. Definitely use his method instead of either of the ones I mentioned.

Jeremy =============
Jeremy Wallace
Designing, Developing, and Deploying Access Databases Since 1995

Take a look at the Developer's section of the site for some helpful fundamentals.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top