+ Reply to Thread
Results 1 to 7 of 7

Obtain Access Table Names via Excel

Hybrid View

  1. #1
    Valued Forum Contributor Macdave_19's Avatar
    Join Date
    03-14-2007
    Location
    Birmingham, England
    MS-Off Ver
    12.0
    Posts
    808

    Question Obtain Access Table Names via Excel

    Hi all,

    I am trying to create a database Puller! it will extract data using SQL via the medium of Excel lol without the user having any knowledge of SQL.

    However i really need to obtain all the table names from a given Database.
    The database' filepath is located in Cell B2 so given that can anyone help me with the code?

    I'll get ya started lol:

    Dim db as Database
    Dim MyDb as string
    
    MyDb = Range("B2").value
    Set db = OpenDatabase(MyDb)
    That's all i got lol!!!

    I'm thinking it could make use of this SQL Script:
    SELECT *
    FROM all_tab_columns
    WHERE Table_Name IS NOT NULL
    but thats something i use in Oracle Developer to obtain table names

    please hep & Ta for reading my thread
    Mr MaGoo
    Magoo.Inc MMVII

    If i've helped please add to my Rep by Clicking on the Blue Scales in the top right hand corner of the post

  2. #2
    Valued Forum Contributor Macdave_19's Avatar
    Join Date
    03-14-2007
    Location
    Birmingham, England
    MS-Off Ver
    12.0
    Posts
    808

    Talking Eureka!!

    I actually did it on my own!!!

    get in for those who care here's how:

    Dim db As Database
    Dim MyDb As String
    Dim InCol As String
    Dim rs As Recordset
    Dim Tbl As TableDef
    
    MyDb = Range("C2").Value
    Set TargetRange = Range("C3")
    Set db = OpenDatabase(MyDb)
    
    i = 0
    For Each Tbl In db.TableDefs
        TargetRange.Offset(0, i).Value = Tbl.Name
        i = i + 1
    Next Tbl
    
    Set rs = Nothing
    Set db = Nothing
    Damn That feels so good!!!! get in!!!

  3. #3
    Forum Contributor Stuie's Avatar
    Join Date
    09-17-2006
    Location
    Suffolk, UK
    MS-Off Ver
    Excel 2003/2007
    Posts
    432
    always feels better to work it out yourself, nice one

  4. #4
    Valued Forum Contributor Macdave_19's Avatar
    Join Date
    03-14-2007
    Location
    Birmingham, England
    MS-Off Ver
    12.0
    Posts
    808

    Talking Cheers

    Nice one Stuie!!!

  5. #5
    Valued Forum Contributor Macdave_19's Avatar
    Join Date
    03-14-2007
    Location
    Birmingham, England
    MS-Off Ver
    12.0
    Posts
    808

    Further info

    You actually end up getting these weird other tables too so i re-wrote it to exlcude them. Here it is:

    Sub GetTableNames()
    
    Dim db As Database
    Dim MyDb As String
    Dim Tbl As TableDef
    
    MyDb = Range("C2").Value ' replace with the whole path if you want.
    Set TargetRange = Range("C3")
    Set db = OpenDatabase(MyDb)
    
    i = 0
    For Each Tbl In db.TableDefs
        Select Case Tbl.Name
            Case "MSysAccessObjects", "MSysAccessXML", "MSysACEs", "MSysObjects", "MSysQueries", "MSysRelationships"
                GoTo CONT
            Case Else
                TargetRange.Offset(0, i).Value = Tbl.Name
    CONT:
                i = i + 1
        End Select
    Next Tbl
    
    Set rs = Nothing
    Set db = Nothing
    
    
    End Sub
    HTH

  6. #6
    Forum Contributor Stuie's Avatar
    Join Date
    09-17-2006
    Location
    Suffolk, UK
    MS-Off Ver
    Excel 2003/2007
    Posts
    432
    i will keep this post in mind as have a project coming up at work soon where i will need to extract a couple of data tables, i would normally just use a data import but i would rather code everything that way you have more control, so you given me a great idea for that

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1