Filling a combo with table names in an mdb through ADO
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.
Re: Filling a combo with table names in an mdb through ADO
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
Re: Filling a combo with table names in an mdb through ADO
the "as database" does not appear in the ado reference.
only in the dao one.
Re: Filling a combo with table names in an mdb through ADO
There is no tabledefs object in ADO!
Re: Filling a combo with table names in an mdb through ADO
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