changeing the connection on a Linked Table

T

TADropik

I'm trying to change the connection of "My_Table" which is a linked table.

Dim tdfTarget as TableDef
Set tdfTarget = CurrentDb.TableDefs("MyTable")
With tdfTarget
.Connect = ";Database=" & "C:\Data\My_Data.mdb"
.RefreshLink
End With

If the existing connection to this Table is a Network location
"Z:\Data\My_Data.mdb" and the Network location does not exist, the .Connect
fails.
 
O

OssieMac

Just a thought and I have not specifically tested this. You haven't deleted
the link before attempting to change its Path have you?

Your code re-establishes an existing link to a new location; I don't think
that it appends a TableDef. With the code you have you don't delete the link
first.

Anyone else with thoughts on this feel free to express them because I am
also interested if there are instances where this does not work because I use
code in a Switchboard Open event to re-establish links between the FE and BE
which I install in the same folder and can use
Application.CurrentProject.Path to identify the location of the BE when I
move the project to another folder and automate re-establishing the links.
 
T

TADropik

Great question.

I have not deleted the link prior to changing the path.

In fact, if I go in to my Link Table Manager, it shows the correct network
path.

What's happening is the Customer is loosing their Network connection.
When that happens I want to automatically link to a local database.
 
O

OssieMac

"Customer is loosing their Network connection"
This might be a clue. Try closing the front end and reopening before running
the code. Could be attempting to write to it and can't change the link while
it is waiting to update the table.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top