Find tables with names with specific prefix in VBA

VBA code below finds tables which names start with specific prefix, e.g. tables with names starting with 'hr'.

Note that you can also do it with query

Code

Public Sub find_hr_tables()
  Dim t As TableDef
  For Each t In CurrentDb().TableDefs
     If Left(t.Name, 2) = "hr" Then Debug.Print (t.Name)
  Next t
End Sub

Rows

  • One row represents a table
  • Scope of rows: all found tables

Sample results

Immediate Window shows names of all tables that starts with "hr"

sample results