Click here to Skip to main content
15,920,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have an access file containing link tables referring to excel file. Each table refer to a specific sheet. The link tables have static connection.
Problem: How can I change the connection of the link tables because the location of the excel file is always changing.
Posted
Comments
Sandeep Mewara 17-Sep-10 14:28pm    
Update from OP:
In access I have created a module with the below function:
Public Sub RefreshODBCLinks(newConnectionString As String)
Dim db As DAO.Database
Dim tb As DAO.TableDef
Set db = CurrentDb
For Each tb In db.TableDefs
If Left(tb.Connect, 4) <> "" Then
tb.Connect = "Excel 12.0;DATABASE=" & newConnectionString & ";HDR=Yes"
tb.RefreshLink
Debug.Print "Refreshed ODBC table " & tb.Name
End If
Next tb
Set db = Nothing
End Sub

Then in the Intermidiate window i have call it and test it.

1 solution

When changing the connection string of a linked table, you must then refresh the link. For example:
Code:
td.Connect = "MS Access;Database=C:\MyBackEnd.mdb;"
td.RefreshLink

The RefreshLink command commits the change to the connection string.
Reply With Quote
:rose::thumbsup:
 
Share this answer
 
Comments
ziadb86 17-Sep-10 5:43am    
can u please insert an entire example because I'm lost? Can I use OleDb?
aayu 17-Sep-10 6:02am    
you use your old database and then go throw the change of connection string and linked table then refresh the link
ziadb86 17-Sep-10 7:21am    
if I opened the database, how can I retrieve the linked tables in order to change their connection string?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900