code_junkie

How to get table names from access?

Nov 11th, 2011
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. SELECT MSysObjects.Name AS table_name
  2. FROM MSysObjects
  3. WHERE (((Left([Name],1))<>"~")
  4. AND ((Left([Name],4))<>"MSys")
  5. AND ((MSysObjects.Type) In (1,4,6)));
  6. order by MSysObjects.Name
  7.  
  8. SELECT
  9. Table_Name = Name,
  10. FROM
  11. MSysObjects
  12. WHERE
  13. (Left([Name],1)<>"~")
  14. AND (Left([Name],4) <> "MSys")
  15. AND ([Type] In (1, 4, 6))
  16. ORDER BY
  17. Name
  18.  
  19. Sub ListAccessTables2(strDBPath)
  20. Dim cnnDB As ADODB.Connection
  21. Dim rstList As ADODB.Recordset
  22.  
  23. Set cnnDB = New ADODB.Connection
  24.  
  25. ' Open the connection.
  26. With cnnDB
  27. .Provider = "Microsoft.Jet.OLEDB.4.0"
  28. .Open strDBPath
  29. End With
  30.  
  31. ' Open the tables schema rowset.
  32. Set rstList = cnnDB.OpenSchema(adSchemaTables)
  33.  
  34. ' Loop through the results and print the
  35. ' names and types in the Immediate pane.
  36. With rstList
  37. Do While Not .EOF
  38. If .Fields("TABLE_TYPE") <> "VIEW" Then
  39. Debug.Print .Fields("TABLE_NAME") & vbTab & _
  40. .Fields("TABLE_TYPE")
  41. End If
  42. .MoveNext
  43. Loop
  44. End With
  45. cnnDB.Close
  46. Set cnnDB = Nothing
  47. End Sub
  48.  
  49. SELECT
  50. Name
  51. FROM
  52. MSysObjects
  53. WHERE
  54. (Left([Name],1)<>"~")
  55. AND (Left([Name],4) <> "MSys")
  56. AND ([Type] In (1, 4, 6))
Add Comment
Please, Sign In to add comment