Solved

Access Linked Tables - Name Changes

Posted on 2016-08-03
4
42 Views
Last Modified: 2016-08-03
Hi,

I have two access databases. The first (database A), is a reference database that simply stores a bunch of data in various tables. The second database (database B), is more of a "computational" database, that uses Linked Tables from database A and runs several different queries/calculations.

My question is this:
Is there anyway to change a table name in database A and automatically have database B recognize this name change in the linked tables and auto update all the queries in database B appropriately? It seems like the answer is no based on what I'm reading online but I figured I would ask the experts...

Thanks.

Brett
0
Comment
Question by:Bcn78
  • 2
4 Comments
 
LVL 49

Accepted Solution

by:
Gustav Brock earned 500 total points
ID: 41741080
You are correct. The answer is no.

But all you need is to link the new table name, then rename the table link to the previous name, thus all queries and code can remain unchanged.

/gustav
0
 

Author Comment

by:Bcn78
ID: 41741098
Got it. That makes sense.

Thanks.
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 41741108
Not really.  Here is the way I would approach it (you don't happen to have Find & Replace do you?)

1.  Rename the table in the backend (database A)
2.  Open database B in design view
3.  Refresh the link to the backend table with the following in the immediate window.  After each of these lines, hit return to execute each statement.  

set db = currentdb
set tdf = db.tabledefs(localTableName)
tdf.SourceTableName = NewName
tdf.refreshlink
set tdf = nothing
set db = nothing

When this is complete, you should be able to double click on the old table name and open the table.

4.  Then change the name of the table in the front end (Database B)
5.  Then, to replace references to that table in all of your saved queries, you can try the following.  But before you do this, MAKE A BACKUP.  Keep in mind, if your tables OldName is embedded in another table name, (like tbl_Clients and tbl_Clients_Family) this is not going to work.
Public Sub ReplaceTableName(OldName, NewName)

Dim db as dao.database
Dim qdf as dao.querydef
Dim strMsg as string

Set db = currentdb
For each qdf in in db.querydefs

    if instr(qdf.sql, OldName) > 0 then
        strmsg = "Warning: using using replace to change the " & vbcrlf _
               & "text of a query could cause the query to stop" & vbcrlf _
               & "functioning properly!" & vbcrlf & vbcrlf _
               & "Replace '" & OldName & "' with '" & NewName & "'" & vbcrlf _
               & "in query: " & qdf.name & vbcrlf & vbcrlf _
               & qdf.SQL
        if msgbox(strmsg, vbcritical + vbYesNo, "Replace string") = vbNo then
            debug.print qdf.name
        else
            qdf.sql = Replace(qdf.SQL, OldName, NewName)
            qdf.close
        end if
    end if

Next

End Sub

Open in new window

This also will not work for queries which are used as the RecordSource for forms or reports or as the RowSource for combo and list boxes if those queries are not saved queries.

HTH
Dale
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 41741126
"But all you need is to link the new table name, then rename the table link to the previous name, thus all queries and code can remain unchanged."

Yes, but if you do it that way, it could be confusing down the road when you go looking for the old table name in Database A, because that will no longer be available.  And people rarely consider that the LocalTableName and the ForeignTableName are not the same.

1.  You could download Rick Fisher's Find & Replace, I believe it has a 30 day trial, that is the best method.  Unfortunately, Rick has not been replying to request for license codes lately, so if you become enamored with his tool, you may not be able to use it for more than 30 days.
2.  Gustav's method is obviously the easiest way to accomplish this, but... (see comments above)
3.  The method I described in my previous post will work for saved queries, with the caveats mentioned in that post.
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question