Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get Table Name in Access 2000

Status
Not open for further replies.

giovy

Programmer
Feb 17, 2000
9
PA
Hi,<br>I need to retrieve all the names of the table in the database. I have been used Table Def for DAO, but don't know how to use in ADO. Any code for solving this problem.<br>Thanks...
 
Try something like this:<br><FONT FACE=monospace><br>&nbsp;&nbsp;&nbsp;&nbsp;rsSchema = conn.OpenSchema(adSchemaTables)<br>&nbsp;&nbsp;&nbsp;&nbsp;Do While Not rsSchema.EOF<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;If rsSchema.Fields(&quot;TABLE_TYPE&quot;) = &quot;TABLE&quot; Then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;foobar = rsSchema.Fields(&quot;TABLE_NAME&quot;)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;End If<br>&nbsp;&nbsp;&nbsp;&nbsp;Loop<br></font>
 
You could also use the ADO Catalogue object which has a syntax similar to that of DAO <br><br>'You can just copy an paste the code below into the <br>'places indicated and it should work<br><br>'Set The Active Connection of the Catalogue<br>'This can be set using the ADO data control<br>'Place the control on a form then access it's <br>'property pages. Select Build(Bottom Right)and follow&nbsp;&nbsp;<br>'the on screen instructions. Cut and Paste the <br>'connection string into your code as follows<br><br>'In the Form declarations<br><br>Dim Cn as AdoDB.Connection<br><br><br>'Assumes that you have a command button called command1<br>Private sub Command1_Click() <br><br>if adConnect('Insert Connection String Here') = true then<br>&nbsp;&nbsp;&nbsp;DisplayTables<br>Else <br>&nbsp;&nbsp;&nbsp;MsgBox &quot;No Connection Could Be Made&quot;,vbokonly+vbinformation,App.title<br>end if <br><br>end sub <br><br>Private sub DisplayTables() <br><br>dim oCat as ADOX.Catalog<br>dim tbl as ADOX.table<br><br>set oCat = new ADOX.Catalog<br><br>'Set the activeConnection for the catalog object <br>oCat.ActiveConnection = cn<br><br>'Loop the catalog collection to enumerate the table names<br>'This assumes that you have a list box called lstTables<br><br>For each tbl in oCat.Tables <br>&nbsp;&nbsp;&nbsp;&nbsp;lstTables.additem tbl.name <br>next tbl <br><br>'You can of course iterate this down further by listing <br>'the columns of each table <br><br>end sub <br><br><br>Private Function ADConnect(ConnStr as String) as Boolean<br><br>set cn = New ADODB.Connection <br><br>with cn<br><br>.ConnectionString = ConnStr<br>.Open <br><br>end With <br><br>'Check if the connection has been established <br><br>if cn.state = adstateopen then <br>&nbsp;&nbsp;&nbsp;adconnect = true <br>else <br>&nbsp;&nbsp;&nbsp;adconnect = false<br>end if <br><br>end function <br><br><br><br>I Hope this is Helpfull <br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top