Solved

Access Linked Tables - Name Changes

Posted on 2016-08-03
4
31 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
Comment Utility
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
Comment Utility
Got it. That makes sense.

Thanks.
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
Comment Utility
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)
Comment Utility
"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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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 …

743 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now