Back To Top


MS Access VBA Get All Tables for versions 2000, 2002, 2003, 2007

Go here To Check if Table exists in VBA.
Go here To Update a Field in VBA.
Go here To Get all Fields in a Table with VBA

The VBA Get All Tables Sample is available for download here in a zipped MS Access Database. The below picture (click to enlarge) shows the Single form and module.

MS Access VBA Get All Tables within a database. 

The following code snippet will use VBA to Return all Tables within a given Access database.



Public Sub
GetAllTables()

  
'References: Microsoft Access 11.0 Object Library, Microsoft DAO 3.6 Object Library
   'Set references by Clicking Tools and Then References in the Code View window
   ' Returns all Table Names that exist in The Current Database.
   ' Accepts
   ' Nothing
   ' Returns All your Table Names and excludes tables with MSys
   ' To include the MSys tables remove the "If Then" statement
   ' To get only the MSys Tables set the "Instr()" statement to True
   'USAGE: GetAllTables

  
On Error GoTo errhandler 'Capture any errors.
  
Dim i As Integer , numTables As Integer , tabName As String
  
'Set the controls focus to print to
  
Form_GetAllTables_Form.txtTblNames.SetFocus
  
'Clear the display
  
Form_GetAllTables_Form.txtTblNames.Text = ""

  
' Loop through all the Tables
  
numTables = CurrentDb.TableDefs.Count - 1

  
For i = 0 To numTables
     
'set string to the Table Name
     
tabName = LCase(CurrentDb.TableDefs(i).Name)

     
'Check for ~ and mssys prefixed Tables and skip them
     
If InStr( 1 , tabName, "msys" ) = False And _
            InStr(
1 , tabName, "~" ) = False Then

        
'Set the controls focus to print to
        
Form_GetAllTables_Form.txtTblNames.SetFocus

        
'display the tables
        
Form_GetAllTables_Form.txtTblNames.Text =   Form_GetAllTables_Form.txtTblNames.Text & _
               vbCrLf
& CurrentDb.TableDefs(i).Name

     
End If
   Next

   Exit Sub

errhandler:
'Capture any Errors

  
With Err
      MsgBox
"Error " & .Number & vbCrLf & .Description, _
            vbOKOnly
Or vbCritical, "GetAllTables"
  
End With
End Sub



For the above VBA Get all Tables Sub in a usable Form with Button, download the Sample database in ZIP format. The sample includes 4 tables with 100 records each. Each table contains 35 Fields.

For further help or suggestions go here: MS Access tutorials, Tables, Queries and later: Forms

You may post this tutorial on your website or in a forum. If you do please maintain a Link to Eraseve AP.



For further MS Access tutorials go here: MS Access tutorials

Go here To Check if Table exists in VBA.

Go here To Get all Fields in a Table with VBA

 

Did you find what you were looking for?
What would you suggest?
mail@eraserve.com
Your Name:
Your Message:
Your Email:

    

 

Custom Search