Results 1 to 2 of 2

Thread: ???Table Names????

  1. #1

    Thread Starter
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    Exclamation

    I was wondering if there is a way to get the names of tables in a database using an SQL statement. I am trying to keep it database independent so it can be used with any ODBC data source. If there is not a way to do this for all database, I would like to see an example using ADO and MS Access.

    Thanks in advance,

  2. #2
    Fanatic Member Psyrus's Avatar
    Join Date
    Jul 2000
    Location
    NJ
    Posts
    602
    ************************************************************

    Dim adoConn as ADODB.Connection
    Dim adoRsFields As ADODB.recordset
    Dim sConn as String
    Dim sCurrentTable as String
    Dim sNewTable as String

    Set adoConn = New ADODB.Connection

    sConn = "Provider=Microsoft.Jet.OLEDB.3.51;Data Source=c:\yourdb.mdb;

    adoConn.open sConn

    Set adoRsFields = adoConn.OpenSchema(adSchemaColumns)

    sCurrentTable = ""
    sNewTable = ""

    Do Until adoRsFields.EOF
    sCurrentTable = adoRsFields!TABLE_NAME
    If (sCurrentTable <> sNewTable) Then
    sNewTable = adoRsFields!TABLE_NAME
    Debug.Print "Current Table: " & RsFields!TABLE_NAME
    End If

    Debug.Print " Field: " & adoRsFields!COLUMN_NAME
    adoRsFields.MoveNext
    Loop

    ************************************************************


    The above code was taken from Beginning VB6 Databases by John Connell from WROX.


    Psyrus


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width