Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default How can I get all table names from MS Access databse

I'm using MS Access and VB. I need to get all table names from database. How
can I do that?


Thank you.


  #2   Report Post  
Posted to microsoft.public.excel.programming
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.




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 459
Default How can I get all table names from MS Access databse

Just for interest, here's a variation which uses ADO only (i.e. not
ADOX) and means you don't have to parse the table names to identify
for system tables:

Sub odwDBTables()
Dim oConn As Object
Dim oRS 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 oRS = oConn.OpenSchema(adSchemaTables, _
Array(Empty, Empty, Empty, "Table"))
Do While Not oRS.EOF

Debug.Print oRS!TABLE_NAME.Value
oRS.MoveNext

Loop
End If

oConn.Close
Set oRS = Nothing
Set oConn = Nothing

End Sub

--

"Bob Phillips" wrote in message ...
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.


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 459
Default How can I get all table names from MS Access databse

....maybe not purely for interest, there may be functionality benefits.
I previously used ADOX exclusively for schema info, then there was one
day when ADOX could not return the schema info I need (primary keys
and unique indices) from a lesser known DBMS (Intersystems Caché,
anyone?) I searched round for an alternative and unexpectedly found it
in the ADO object model, being OpenSchema. It's very functionally
rich: take a look at:

http://msdn.microsoft.com/library/de...schemaenum.asp

--

(onedaywhen) wrote in message . com...
Just for interest, here's a variation which uses ADO only (i.e. not
ADOX)...

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating a databse from several Excel files JS Excel Discussion (Misc queries) 0 June 29th 06 02:39 PM
Excel Spreadsheet from Access. List of names changes as names are Gordy w/Hi Expectations Excel Discussion (Misc queries) 1 October 21st 05 03:30 AM
Making A Databse system on Excel? Lwotton Excel Discussion (Misc queries) 2 January 4th 05 03:27 PM
retrieving table names from Excel and Access sources using ADO masayoshi hayashi Excel Programming 3 December 10th 03 09:35 AM
Create a Databse using VBA Michael Rekas Excel Programming 0 August 23rd 03 04:42 PM


All times are GMT +1. The time now is 08:35 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"