
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: