Results 1 to 9 of 9

Thread: Extracting table names and field names from Access 2000 db via code

  1. #1
    Jethro
    Guest

    Question Extracting table names and field names from Access 2000 db via code

    This has to be possible, but can't suss it at all

  2. #2
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    VB Code:
    1. 'Add a reference to Microsoft ADO Ext. X.X For DLL And Security
    2. 'Add a reference to Microsoft ActiveX Data Objects X.X Library
    3. Option Explicit
    4.  
    5. Private cat As ADOX.Catalog
    6. Private tbl As ADOX.Table
    7. Private cnn As New ADODB.Connection
    8. Private col As New Column
    9.  
    10. Private Sub Command1_Click()
    11.     Set cat = New ADOX.Catalog
    12.     Set tbl = New ADOX.Table
    13.    
    14.     'setup db connection
    15.     cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Program Files\Microsoft Visual Studio\VB98\BIBLIO.MDB"
    16.     Set cat.ActiveConnection = cnn
    17.    
    18.     'loop through all tables, and all fields in each table.
    19.     For Each tbl In cat.Tables
    20.         Debug.Print tbl.Name
    21.         For Each col In tbl.Columns
    22.             Debug.Print vbTab & vbTab & col.Name
    23.         Next col
    24.     Next tbl
    25.    
    26.     'close the connection
    27.     cnn.Close
    28.     Set cnn = Nothing
    29. End Sub

    should get u going Jello
    -= a peet post =-

  3. #3
    Jethro
    Guest
    Hey thanks Peet .... that should do the trick cool...

  4. #4
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    good

    CoolColorfullMovingJelloAvatar DF is doing avatars all day long?

    *mumble*gmprrs* damn competition !
    -= a peet post =-

  5. #5
    Jethro
    Guest
    She's doing a few for the latest TT party next friday ... of course she would never think of competing with Ye Olde Viking Avatars...

    Just plowing through your code post at the moment. Thanks again peet a real life saver, have to demo a beta early next week

  6. #6
    Addicted Member JasonGS's Avatar
    Join Date
    May 2000
    Location
    California
    Posts
    155
    You can also query the system tables in the database. To view them, goto Tool / Options in Access and check the "System objects" in the "Show" group.

    To get a recordset of all tables, you can issue the SQL statement: SELECT [Name] FROM [MSysObjects] WHERE (type = 1)

  7. #7
    Jethro
    Guest
    Thanks Jason unfort need to do it via code.


    OKie dokie Peet that worked a treat got the following happening

    a) Connect to mdb

    b) Combo drop down of files

    c) User selects a file

    d) Field names, type, and size displayed.

    Two further problems.

    1) After the user selects a file, it would appear that l have to loop through the table list again to get Tbl.Name = combo select, in order to display the field details. Is there a better way of doing this.

    2) Field types are coming back as integers, e.g 130 = text. Not a huge problem but anyway of translating it without resorting to a Select Case statement and manually translating it.

  8. #8
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    morning Jethro,

    1) cant think, and don know, of a better/smarter way to do it

    2) I use select case, have not found a better way. There are built
    in const. for field type when using DAO.

    VB Code:
    1. Private Function GetVarType(dbFieldTypeConst As Long) As String
    2.     Select Case dbFieldTypeConst
    3.     Case dbText
    4.         GetVarType = "String"
    5.     Case dbBoolean
    6.         GetVarType = "Boolean"
    7.     Case dbBigInt
    8.         GetVarType = "LongInt"
    9.     Case dbDate
    10.         GetVarType = "String"
    11.     Case dbDouble
    12.         GetVarType = "Double"
    13.     Case dbInteger
    14.         GetVarType = "Integer"
    15.     Case dbLong
    16.         GetVarType = "Long"
    17.     Case dbMemo
    18.         GetVarType = "String"
    19.     Case dbSingle
    20.         GetVarType = "Single"
    21.     Case dbText
    22.         GetVarType = "String"
    23.     Case Else
    24.         GetVarType = "String"
    25.     End Select
    26. End Function

    use that in an old app I'v made, there are probably const. for the ADOX returned types aswell, I'd use them. (don't know what they
    are though )
    -= a peet post =-

  9. #9
    Jethro
    Guest
    Thanks again oh great viking coding god


    Okie dokie .... expect more questions....

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