Testing for table existence & listing available tables 
Author Message
 Testing for table existence & listing available tables

I need to test for a tables existence by name to prevent overwriting - how
is this achieved?

Also, how would I list available tables in a list box?

How does the ordinal numbering system work with reference to tables?

Cheers

Ken



Mon, 04 Dec 2000 03:00:00 GMT  
 Testing for table existence & listing available tables

Quote:
>I need to test for a tables existence by name to prevent overwriting - how
>is this achieved?

The quickest way is to try to set a reference to the tabledef and trap
the error that occurs if it isn't there. Something like:
Function IsTable(strTestName as string) as boolean
  Dim db as database
  Dim tdf as tabledef
  Set db=Currentdb
  On error resume next
  Set tdf=db.Tabledefs(strTestName)
  IsTable=(err.number=0)
  set tdf=nothing
  set db=nothing
End Function

Quote:
>Also, how would I list available tables in a list box?

There are 2 ways: use a query against MSysObjects (which you can look
at by choosing to view System Objects on the View tab of the Options
dialog box). This query would be something like this, to see native
and attached tables, but not system tables:
SELECT MSysObjects.Name
FROM MSysObjects
WHERE (((MSysObjects.Type)=1 Or (MSysObjects.Type)=6) AND
((MSysObjects.Flags)=0));

Or you can create a callback function (see the RowSourceType help
topic) that uses DAO to loop through the tabledefs collection, and
uses the Attributes property to filter out system tables.

Quote:
>How does the ordinal numbering system work with reference to tables?

Not sure what you mean. Tabledefs don't have an OrdinalPosition
property the way fields in a tabledef do. If you mean the index in the
tabledefs collection, that would have to do with how and when the
tabledefs were added to the collection. I wouldn't rely on that index
for anything important.

 -- Andy

Quote:

>Cheers

>Ken



Mon, 04 Dec 2000 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Testing for Existence of Table

2. Test for table existence

3. Test for the existence of a table

4. Testing for table existence

5. Testing for table existence

6. Testing for table existence

7. Testing for table existence

8. Testing the existence of a table

9. Display & Select available Tables??/

10. VB6 & Access - howto get list of tables & list of fields in a table

11. Using a Treeview to List Tables & Fields

12. List SQL Server Tables & Fields

 

 
Powered by phpBB® Forum Software