Click to See Complete Forum and Search --> : Filling a combo with table names in an mdb through ADO


FireRider
September 15th, 1999, 04:29 PM
Hi.
I'm trying to make a program that shows a user a list of available tables in a database he selects, either through SQL ADO or Jet.
through jet i can't find a way for the user to select a table.
i don't know how to do something similer to "Select * from sysobjects" in SQL.
how do i do that?
it should be like the combo you get when building a connection string in Adodc when chooseing a table to connect to under thew "adcmdTable" catagory.
thx.


---------



Life is like an analogy.

Vlad Chapranov
September 15th, 1999, 10:26 PM
Use this. It's very similar with ADO or DAO:
Place Combo1, Command1 on Form1, add reference to DAO or ADO object library and copy this code. Replace DBName with appropriate.

option Explicit
private db as Database

private Sub Command1_Click()
Dim intIndex as Integer
for intIndex = 0 to db.TableDefs.Count - 1
Combo1.AddItem db.TableDefs(intIndex).Name
next intIndex
End Sub

private Sub Form_Load()
set db = OpenDatabase("DBName")
End Sub



Don't forget to close all open objects in unload event.
HTH
Vlad

September 16th, 1999, 01:58 AM
the "as database" does not appear in the ado reference.
only in the dao one.

Lothar Haensler
September 16th, 1999, 02:08 AM
There is no tabledefs object in ADO!

Lothar Haensler
September 16th, 1999, 02:09 AM
you need to use the OpenSchema method in ADO

Dim cnn1 as ADODB.Connection

Dim rstSchema as ADODB.Recordset

set cnn1 = DataEnvironment1.Connection1

cnn1.Open strCnn

set rstSchema = cnn1.OpenSchema(adSchemaTables)

Dim i as Integer

Do Until rstSchema.EOF

for i = 0 to rstSchema.Fields.Count - 1

List1.AddItem rstSchema.Fields(i).Name & " = " & rstSchema.Fields(i).Value

next i

List1.AddItem "-------------------------------"

rstSchema.MoveNext

Loop

rstSchema.Close

cnn1.Close