If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Delphi, C etc > MS Access Tables

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-22-04, 04:52
rgndrp rgndrp is offline
Registered User
 
Join Date: Jan 2003
Posts: 10
MS Access Tables

Hi all,

Does anyone know how I can list the table names (and fields in the tables) in an access database from within a vb application?

thnx
Reply With Quote
  #2 (permalink)  
Old 03-22-04, 22:58
SCIROCCO SCIROCCO is offline
Registered User
 
Join Date: Mar 2004
Location: www.scirocco.ca
Posts: 346
Re: MS Access Tables

Either us ADOX (ADO extension library) or use the OpenSchema method of the Connection Object. Here is an example:

Private Sub DisplayInfo()

Dim cn as ADODB.Connection
Dim rsTables As ADODB.Recordset
Dim rsFields As ADODB.Recordset

Set cn = new ADODB.connection

cn.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=DataBaseName;Data Source=ServerName"

cn.Open

Set rsTables = cn.OpenSchema(adSchemaTables)

Do While Not rsTables.EOF

If oRsTables("TABLE_TYPE").Value = "TABLE" Then
Debug.Print "Table: " & rsTables("TABLE_NAME").Value

Set oRsFields = cn.OpenSchema(adSchemaColumns, _ Array(Empty, Empty,
oRsTables("TABLE_NAME").Value, Empty))

Do While Not rsFields.EOF
Debug.Print " Column: " & oRsFields("COLUMN_NAME").Value rsFields.MoveNext
Loop

Debug.Print

End If

rsTables.MoveNext

Loop

End Sub
__________________
http://www.scirocco.ca/images/banner...occobanner.gif

Download for FREE the ADO/DAO Data Controls that makes life EASIER developing database applications in: VB, FoxPro, Access, VC++, .NET etc... Navigate, Add New, Delete, Update, Search, Undo and Save your changes. Supports Disconnected Recordsets and Transactions!

Or try our Ask An Expert service to answer any of your questions!
Reply With Quote
  #3 (permalink)  
Old 03-23-04, 03:18
rgndrp rgndrp is offline
Registered User
 
Join Date: Jan 2003
Posts: 10
Re: MS Access Tables

That was exactely what i needed, thanks alot!
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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