PDA

Click to See Complete Forum and Search --> : RetrievingTable Names


chongo 2002
Nov 14th, 2000, 08:28 PM
How do you retrieve multiple table names from a database and display them in a listbox using dao?

Surgeon
Nov 15th, 2000, 03:34 AM
Let's assume that you have a VB form with one simple data control named Data1, one listbox named List1, and one command button named Command1. Furthermore, I guess you're connecting to an Access database. That means that in design mode, you already entered something like "c:\...\something.mdb" in the DatabaseName property of your Data control.

So just write this code for the click event of your command button :

Private Sub Command1_Click()
Dim i As Long
Dim n As Long
n = Data1.Database.TableDefs.Count
For i = 0 To n - 1
List1.AddItem Data1.Database.TableDefs(i).Name, i
Next i
End Sub

and see what happens. I must warn you though, the Database property of the Data control is ONLY available in the proffesional and the enterprise versions of VB. Another thing : you'll notice that the first 6 tablenames retrieved are some funny names you won't recognize in your database. I'll let you figure that out for yourself (don't want to spoil all the fun :-)

Hope it will help ya.

chongo 2002
Nov 15th, 2000, 02:20 PM
Yeah thanks that did the trick i just have to remove the other names by a query.