Results 1 to 3 of 3

Thread: RetrievingTable Names

  1. #1

    Thread Starter
    Lively Member chongo 2002's Avatar
    Join Date
    Apr 2000
    Posts
    106

    Question

    How do you retrieve multiple table names from a database and display them in a listbox using dao?

  2. #2
    Lively Member Surgeon's Avatar
    Join Date
    Oct 2000
    Posts
    121
    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.

  3. #3

    Thread Starter
    Lively Member chongo 2002's Avatar
    Join Date
    Apr 2000
    Posts
    106
    Yeah thanks that did the trick i just have to remove the other names by a query.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width