Access VBA: Is there an internal VBA function that returns the current table name?

Anonymous
2016-12-06T22:17:10+00:00

Using an update query to store "current table name" to a new field.

I'm importing several text files into a Microsoft Access 2016 database. Before I starting appending all 25 tables into one common table, I'm needing to store the original text file's "name" into a newly created "Imported_Source" field. Doing a "F2", copy source file name, then placing argument into update query is way too time consuming. It would be nice if Access had a library function perhaps  <me.filename> or a function like <Get_MeTableName>. Then  I could place that function into the update argument of an Update Query.

Thanks!

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
{count} votes

14 answers

Sort by: Most helpful
  1. ScottGem 68,780 Reputation points Volunteer Moderator
    2016-12-08T02:49:11+00:00

    I don't know what your issue is. Or what your problem with looping. Looping is an integral part of any programming automation.

    You are trying to make what is a n easy and simple task into something harder by looking for something that doesn't exist. No matter how you cut it, the way to do this is to loop through your tables and for each table, generate and execute an query. Either a Query that updates a field in the table or appends the data to a master table, setting the value of a field. I gave you coding examples you can use.

    But if you want to waste time looking for something that doesn't exist or trying to make a a simple task harder, that's up to you.

    0 comments No comments
  2. Anonymous
    2016-12-08T14:59:20+00:00

    Thank you sir for your valued time. In my situation, I could not get your logic to work. Perhaps the two dozen imports made matters worse. Focusing on a single UPDATE query, returning it record source name to a new field, should have been my starting point. Have a nice day!

    0 comments No comments
  3. ScottGem 68,780 Reputation points Volunteer Moderator
    2016-12-08T15:27:05+00:00

    So show me the code you used and we can get it to work.

    0 comments No comments
  4. Anonymous
    2016-12-09T03:31:08+00:00

    THANKS for your fast response. I'm still perplexed. The below code, shown before, was hand copied from an Access 2000 text book. In the immediate window, I'm able to see the result of tables plus many unknown system tables.  I will study your notes and get back to you. If your able, work with this code.  Thanks again.

    Sub iterateAllTabes()

    Dim vnt As Variant

        With CurrentData  ' comment CurrentData object

            For Each vnt In .AllTables

            Debug.Print vnt.Name

            Next vnt

        End With       

    End Sub

    0 comments No comments