Is their any way to get the table names and column names in a table through an SQL statement in Access 2000? I know SQL Server and Oracle both have them (select table_name from user_tables).
This is off the top of my head but it should be close.
Dim db As DAO.Database
Dim TDef As DAO.TableDef
Dim Fld As DAO.Field <= Don't know if you need DAO here
Set DB = CurrentDB
For Each TDef in db.TableDefs
Debug.Print TDef.Name
For Each Fld in TDef.Fields
Debug.Print Fld.Name
Next Fld
Next TDef
Basically what you are doing is spinning through the TableDef collection for the database. If you single step the code above and turn view locals on, you can mess around with the DB object to find lots of interesting stuff.
While Not rs.EOF
Debug.Print rs!table_name
Set rs2 = cn2.OpenSchema(adSchemaColumns, _
Array(Empty, Empty, "" & rs!table_name & "")
While Not rs2.EOF
Debug.Print " " & rs2!column_name
Debug.Print " " & rs2!data_type
Debug.Print " " & rs2!description
rs2.MoveNext
Wend
rs.MoveNext
Wend
If you need data_type it is a number that can be checked back against the constants in Access definitions. i.e. 3 = adInteger look in datatypeEnum for more definitions.
If anyone is still interested you can use the following SQL to get the table names:
Select Name From MySysObjects Where Type = 1 And Left(Name,5) <> "MySys"
This is especially useful for displaying in a list box.
To display field names in a list box set the RowSourceType to Field List and the set the RowSource to the table or query whose fields you want displayed.
Combining a list box with the table names in it and several list boxes for field lists, you can use the doubleclick event of the list box with the table names to change the RowSource of a field name list box to the table selected allowing the user a lot of flexibility in selecting tables and fields for a variety of uses (queries, reports in particular come to mind)
Would that be the same as whether nulls are allowed or not.
rs!is_nullable
Go through the schema for 1 table and print out the fields collection name this will give you all the fields or attributes that can be checked. See previous example.
Dim fld As Field, indx As Integer
Set rs2 = cn2.OpenSchema(adSchemaColumns, _
Array(Empty, Empty, "" & rs!table_name & "")
For indx = 0 To rs2.Fields.Count - 1
Debug.Print " " & rs2.Fields(indx).Name
Next
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.