Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2003
    Posts
    10

    Unanswered: MS Access Tables

    Hi all,

    Does anyone know how I can list the table names (and fields in the tables) in an access database from within a vb application?

    thnx

  2. #2
    Join Date
    Mar 2004
    Location
    www.scirocco.ca
    Posts
    346

    Re: MS Access Tables

    Either us ADOX (ADO extension library) or use the OpenSchema method of the Connection Object. Here is an example:

    Private Sub DisplayInfo()

    Dim cn as ADODB.Connection
    Dim rsTables As ADODB.Recordset
    Dim rsFields As ADODB.Recordset

    Set cn = new ADODB.connection

    cn.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=DataBaseName;Data Source=ServerName"

    cn.Open

    Set rsTables = cn.OpenSchema(adSchemaTables)

    Do While Not rsTables.EOF

    If oRsTables("TABLE_TYPE").Value = "TABLE" Then
    Debug.Print "Table: " & rsTables("TABLE_NAME").Value

    Set oRsFields = cn.OpenSchema(adSchemaColumns, _ Array(Empty, Empty,
    oRsTables("TABLE_NAME").Value, Empty))

    Do While Not rsFields.EOF
    Debug.Print " Column: " & oRsFields("COLUMN_NAME").Value rsFields.MoveNext
    Loop

    Debug.Print

    End If

    rsTables.MoveNext

    Loop

    End Sub
    http://www.scirocco.ca/images/banner...occobanner.gif

    Download for FREE the ADO/DAO Data Controls that makes life EASIER developing database applications in: VB, FoxPro, Access, VC++, .NET etc... Navigate, Add New, Delete, Update, Search, Undo and Save your changes. Supports Disconnected Recordsets and Transactions!

    Or try our Ask An Expert service to answer any of your questions!

  3. #3
    Join Date
    Jan 2003
    Posts
    10

    Re: MS Access Tables

    That was exactely what i needed, thanks alot!

Posting Permissions

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