| Description:This will allow you to fill a standard ListBox control with all the exsisting Tables in a database. It will also let you change recordsources when clicking On the control.For instance, If I have a database full of products that i want catagorized but I don't want to design queries or use a lot of code, Then I can make a database With separate tables For each catagory, and insert Identical Fields in them. That way the user will see a list box full of catagories, and clicking them will switch the table. Assumes:Create a new form with a Timer control (Timer1), a ListBox control (List1), and a Data control (data1). Make sure Data1 has a valid database selected. Private Sub Form_Load() ' Set timer interval to be 100 milliseconds and enable it. If you paste the timer code directly into ' the Form_Load sub, there will not be enough time for the database to initialize. Timer1.Interval = 100 Timer1.Enabled = True End Sub Private Sub Timer1_Timer() Dim AddMe As String 'Find the number of TableDefs that are in Data1 For i = 0 To Data1.Database.TableDefs.Count - 1 AddMe = Data1.Database.TableDefs(i).Name 'Check to make sure it doesn't add the System Tables to your list ' You can remove this if you need the system tables too. just make this line "If AddMe <> "" Then List1.AddItem AddMe" If AddMe <> "" And AddMe <> "MSysACEs" And AddMe <> "MSysObjects" And _ AddMe <> "MSysQueries" And AddMe <> "MSysRelationships" Then List1.AddItem AddMe Next i 'Disable timer so procedure doesn't run again Timer1.Enabled = False End Sub Private Sub List1_Click() 'Change the RecordSource to the user's selection. Data1.RecordSource = List1.Text 'Refresh Database and any other controls that don't refresh automatically. Data1.Refresh End Sub |
Filling a ListBox with the Tables in a database |
Express News India | Freelance ecommerce web development India