Get the Current Table Name in Microsoft Access VBA
Question details
The user wants to write each manually imported Access table's name into a field in that table using 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.
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.
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.
In Access, press Alt+F11 to open the VBA editor, then choose Insert > Module.
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
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.
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.

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.

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.




