devxlogo

Retrieving Table List

Retrieving Table List

Question:
How can I get the tables within an Access2.0database to show in a list box? The user willspecify a database in a text box and I want themto be able to choose which table they want to workwith. Also, once I get the table, how can I havethe fields of that table show up in another listbox? I have tried using the List Fields Method tono avail.

Answer:
You can loop through the TableDefs collection, which is a property of the Database object. Those are all the tables in the currently active database. You can add them into the list box with the AddItem method. Here’s an example:

Dim db as DatabaseDim td as TableDefSet db = OpenDatabase(“Filename”)ListBox.ClearFor Each td In db.TableDefs   ListBox.AddItem td.Name   db.TableDefs.MoveNextLoop

devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist