Others

Get the Current Table Name in Microsoft Access VBA

Kushani NimanthikaKushani Nimanthika Nov 25, 2026 869 views

Question details

The user wants to write each manually imported Access table's name into a field in that table using VBA.

Get the Current Table Name in Microsoft Access VBA
Product
Microsoft Access
Device & OS
not provided
Scenario
After importing files through the Access ribbon, the user wants to populate an Imported_Source field with the corresponding table name, without path information.
Observed behavior
Access does not provide a table equivalent of the Me keyword available on forms and reports. The user can enumerate tables and retrieve each table's Name property.
Before you start

Identify a naming pattern that selects only the imported tables you intend to update, and confirm each has an Imported_Source field that can store the table name. The update will overwrite that field in every row of each selected table.

Solution 1Recommended

Loop through Access TableDefs and update each imported table

Use each TableDef's Name property to build an UPDATE statement for selected local tables.

The example selects local tables whose names start with Imported_. Change the prefix to match your tables, or replace the condition with another explicit selection rule.

1
Open a VBA module

In Access, press Alt+F11 to open the VBA editor, then choose Insert > Module.

2
Add the update procedure

Paste this procedure into the module: Public Sub UpdateImportedSources() Dim db As DAO.Database Dim tdf As DAO.TableDef Dim strSQL As String Set db = CurrentDb For Each tdf In db.TableDefs If tdf.Connect = "" And Left$(tdf.Name, 9) = "Imported_" Then strSQL = "UPDATE [" & tdf.Name & "] SET [Imported_Source] = '" & Replace(tdf.Name, "'", "''") & "'" db.Execute strSQL, dbFailOnError End If Next tdf End Sub

3
Check the table selection

Edit the Imported_ prefix and its length in Left$ to match your imported tables. In the Access Navigation Pane, check that every table matching the condition has an Imported_Source field.

4
Run and verify

Place the cursor inside UpdateImportedSources in the VBA editor and press F5. Then open a selected table from the Navigation Pane and check its Imported_Source values.

Loop through Access TableDefs and update each imported table
The update affects every row: The statement has no WHERE clause, so it replaces Imported_Source in all rows of each selected table. A missing field or another execution error stops the procedure.
Free Microsoft Office alternative

Work with imported spreadsheet data in WPS Office

WPS Office is a free, lightweight alternative with a familiar interface for working with documents and spreadsheets. Its Microsoft Office format compatibility makes it easy to move existing files, but it does not run Microsoft Access databases or fix Access VBA code.

Review and edit imported spreadsheet data in WPS Spreadsheets.Open and save Microsoft Excel formats such as XLSX.Use a familiar interface for common spreadsheet tasks.Move existing Office documents into a lightweight, easy-to-use suite.
microsoft office alternative - wps office

Frequently Asked Questions

Can I use Me to get a table name in Access VBA?

No. Me refers to the current form or report in its code module; it does not identify a current table. Loop through CurrentDb.TableDefs and read each TableDef's Name property instead.

How do I update only the tables I imported?

Add an explicit condition inside the TableDefs loop, such as a distinctive table-name prefix. Check the matching names in the Navigation Pane before running the UPDATE statement.

What happens if a selected table has no Imported_Source field?

The UPDATE statement will fail and the procedure will stop. Open each selected table in Design View and confirm that Imported_Source exists before running the procedure.

Does the table name include the imported file's path?

No. The TableDef Name property returns the name of the Access table, not the path of the original imported file.