Let's say you wanted to place a restriction on one of the elements, say TABLE_NAME,
A certain database in the catalog is called XYZ, and there are 5 tables in the database, one of which is called MyTable.
If you want all records returned only info on the "MyTable" table, instaed of ALL 5 tables, you would use a restriction for the 3rd element:
Now you can only view the table "MyTable" and it's column, index, key structure, but not the other 4 tables in the database.
So, how to use this example:
Say you want to find out if a certain table in a database exists.
You may do something like this:
Public Function TableExists(conn As ADODB.Connection, ByVal sTableToFind As String) As Boolean
Dim rsADO As ADODB.Recordset
sTableToFind = UCase$(sTableToFind)
Set rsADO = conn.OpenSchema(adSchemaTables)
With rsADO
Do Until .EOF
If UCase$(.Fields("TABLE_NAME".Value) = sTableToFind Then
TableExists = True
Exit Do
End If
.MoveNext
Loop
.Close
End With
Set rsADO = Nothing
End Function
This works fine except it has one drawback:
To find just one table it needs to loop through all tables, making it lesss efficient, and very ineffecient if there are dozens of tables and hundreds, or even thousands, of fields in the database.
Not only does it take longer to get the structure in order to find out if one little table exists or not, the recordset is larger, wasting resources.
Let's use the same example but with a restriction on the TABLE_NAME.
Public Function TableExists(conn As ADODB.Connection, ByVal sTableToFind As String) As Boolean
Dim rsADO As ADODB.Recordset
Set rsADO = conn.OpenSchema(adSchemaTables, Array(Empty, Empty, sTableToFind, Empty))
TableExists = Not (rsADO.EOF And rsADO.BOF)
rsADO.Close
Set rsADO = Nothing
End Function
Now, not only is the proceedure alot smaller, and we do not need to pay attention to the CASE of the table name, but it will run alot faster.
It is alot more effecient.
You would need to pass TABLE or LINK as the last argument...but not both.
You can leave the argument Empty, then use the Filter Method:
rsado.Filter="TABLE_TYPE = 'LINK' OR TABLE_TYPE = 'TABLE'"
You have 5 Types avalable for a JET MDB:
ACCESS TABLE = MS Access system table
LINK = A Linked table to a non-ODBC data source
PASS-THROUGH = A Linked table to an ODBC data source
SYSTEM TABLE= A Jet system table
TABLE = your basic table
VIEW = A JET Query
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.