Results 1 to 5 of 5

Thread: Listing tables

  1. #1

    Thread Starter
    Hyperactive Member parkes's Avatar
    Join Date
    Jan 1999
    Location
    Unitied Kingdom
    Posts
    303
    I've got an Access database and I need to get a list of tables that I've created. How can I do this?
    Thanks in advance for any help provided.

    VB 6 Enterprise Edition SP4
    ADO, SQL 7/2000, ASP and some JavaScript


    >> Life goes on, but for how long? <<
    If you can smile when things go wrong, you have someone in mind to blame

  2. #2
    Lively Member
    Join Date
    Jul 2000
    Location
    Stockholm, Sweden
    Posts
    83
    Access has system tables as every (?) SQL database. You get the table names with the query below. But I dont know fore sure how to remove the system tables from the result but you could also test on the name.

    SELECT MSysObjects.Name
    FROM MSysObjects
    WHERE (((MSysObjects.Type)=1));

    Check the help in Access about System tables.

    Or simply view the system tables with :

    To make system objects visible, click Options on the Tools menu, click the View tab, and then select the System Objects check box.

    Hope this helps, I have never used it by myself.


    Yesterday, all my troubles seemed so far away...
    Help, I need somebody, Help...
    Now MCSD and still locking for intresting job in the south parts of Stockholm, Sweden.

  3. #3
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657
    The following code will list your tables to a listbox:
    Code:
        Dim db      As Database
        Dim td      As TableDef
    
        List1.Clear
    
        Set db = OpenDatabase("C:\Whatever\MyData.mdb")
    
        ' Loop thru and add the table name to the listbox
        For Each td In db.TableDefs
            If Left$(td.Name, 4) <> "MSys" Then
                List1.AddItem td.Name
            End If
        Next
    
        db.Close
    
        Set td = Nothing
        Set db = Nothing
    "It's cold gin time again ..."

    Check out my website here.

  4. #4
    New Member
    Join Date
    Aug 2000
    Posts
    10
    The following should work from an Access module:

    Option Base 0
    Option Explicit
    Sub tablenames()
    Dim dbsData As Database, tdfTable As TableDef, a() As String, i As Integer, j As Integer
    Set dbsData = CurrentDb
    i = 0
    j = 0
    For Each tdfTable In CurrentDb.TableDefs 'loop through each tabledef in collection tabledefs
    'assume dbsystemobject attribute is set correctly
    If (tdfTable.Attributes And dbSystemObject) = False Then ' could also test dbhiddenobject
    ReDim Preserve a(j)
    a(j) = dbsData.TableDefs(i).Name ' record table names in an array
    j = j + 1
    End If
    i = i + 1
    Next tdfTable
    'you could then dump the array to excel
    '(you might have to select excel objects under tools:references for this to work) :-
    Dim objExcel As Excel.Application
    Set objExcel = New Excel.Application
    objExcel.Application.Workbooks.Add
    objExcel.Application.Range("a1").Select
    For j = 0 To UBound(a)
    objExcel.ActiveCell.Value = a(j)
    objExcel.ActiveCell.Offset(1, 0).Select
    Next j
    objExcel.Application.Visible = True
    End Sub

    Alex

    [Edited by alexn on 08-21-2000 at 10:55 PM]

  5. #5
    New Member
    Join Date
    Aug 2000
    Posts
    10
    how do i get the code in my reply to retain vb format??

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