View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Bob Phillips[_6_] Bob Phillips[_6_] is offline
external usenet poster
 
Posts: 11,272
Default How can I get all table names from MS Access databse

Mlaky,

This should do what you want

Sub DBTables()
Dim oConn As Object
Dim oCat As Object
Dim oTable As Object
Dim sConnString As String
Dim sFileName As String

sFileName = "D:\Development\vb\hospital db\TBIcontacts.mdb"

sConnString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & sFileName & ";"

Set oConn = CreateObject("ADODB.Connection")
On Error Resume Next
oConn.Open sConnString
If Err.Number < 0 Then
MsgBox "Error reading file " & sFileName
Else
On Error GoTo 0
Set oCat = CreateObject("ADOX.Catalog")
Set oCat.ActiveConnection = oConn

For Each oTable In oCat.Tables
If Left(oTable.Name, 4) < "MSys" Then _
Debug.Print oTable.Name
Next oTable
End If

oConn.Close
Set oCat = Nothing
Set oConn = Nothing

End Sub

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Mlaky" wrote in message
...
I'm using MS Access and VB. I need to get all table names from database.

How
can I do that?


Thank you.