VBA code to show table names

To show all table names in the current database with VBA code, you can do as the following:

-Create a new form

-Drop one button control on the form

-Drop one list box on the form

-To display all tables in the current database in the list box, when the user clicks the button, you need to attached the following code to the Click event of the button:

Private Sub Command0_Click()
  Dim tb As TableDef
  List0.RowSourceType = "Value List"
  For Each tb In CurrentDb.TableDefs
      List0.AddItem tb.Name
  Next

End Sub

-Open open a table when you double-click it in the list box, you need to attach the following code to DblClick event of the list box:

Private Sub List0_DblClick(Cancel As Integer)
   DoCmd.OpenTable List0.ItemData(List0.ListIndex), acViewNormal

End Sub

Posted by: Dara | post date: 11-03-2012 | Subject: VBA for MS Access

vba access tip



    This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
    C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.