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...
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 <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> DisplayTables<br>Else <br> MsgBox "No Connection Could Be Made",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> 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> adconnect = true <br>else <br> adconnect = false<br>end if <br><br>end function <br><br><br><br>I Hope this is Helpfull <br>
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.