Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

To retrieve table names from Access DataBase using vba

0

I need to get only all the table names from any database using vba?code,

If anyone has a solution for this please share it.

ThankYou

Answer
Discuss

Answers

0

Try this code

Sub Get_Access_Tables()

Dim DB As Database
Dim T As TableDef
Dim filPath As String

With Application.FileDialog(msoFileDialogOpen)
  .AllowMultiSelect = False
  .Show

  filePath = .SelectedItems(1)

End With

Set DB = OpenDatabase(filePath)

For Each T In DB.TableDefs
  MsgBox T.Name
Next

End Sub

To run this you have to enable the correct reference library in VBA.

In the VBA Editor window, go to ToolsReferences and put a check mark next to the entry that looks like this:

Microsoft Office ##.# Access database engine Object Library

or

Microsoft DAO Library 3.6

Use the last one if you are on an older version of Excel.

The # sign stands for a number; in my case it is 16.0

Discuss


Answer the Question

You must create an account to use the forum. Create an Account or Login