Whne I change the "connect" property to point from a database in the file system to sql server it works fine:
Sub execute()
Dim tdf As TableDef, db As Database
Set db = CurrentDb
db.TableDefs.Refresh
'Debug.Print ("----------")
For Each tdf In db.TableDefs
With tdf
If Left$(.Connect, Len(";DATABASE=")) = ";DATABASE=" Then 'checks if this table is linked to a file
Debug.Print ("Old Connection:" & .Connect)
.Connect = "ODBC;DRIVER=SQL Server;SERVER=MYCOMPUTER\SQLEXPRESS;APP=Microsoft Office XP;WSID=MYCOMPUTER;DATABASE=gendbSQL;Trusted_Connection=Yes"
tdf.RefreshLink
End If
End With
Next
Set tdf = Nothing
Set db = Nothing
End Sub
but when after I change it back from ODBC to point back at he file system, when "refreshLink" is called, The "Select Data Source" window pop-ups. what should I do, and how can I eliminate this
(here is the code I use the second time):
Sub undo()
Dim cmdBackup As DAO.QueryDef
Set cmdBackup = CurrentDb.QueryDefs("QryRestoreLinks") 'a query to retrive the names of the links that were changed
Dim tdf As TableDef, db As Database
Set db = CurrentDb
db.TableDefs.Refresh
For Each tdf In db.TableDefs
With tdf
cmdBackup.Parameters("@name") = .Name
Debug.Print (.Name)
Dim rs As DAO.Recordset
Set rs = cmdBackup.OpenRecordset
If Not rs.EOF Then
Debug.Print ("undo" & .Connect)
.Connect = rs!Connection
Debug.Print ("undo_new" & .Connect)
tdf.RefreshLink 'HERE IS THE PROBLEM
End If
End With
Next
Set tdf = Nothing
Set db = Nothing
End Sub

Problem with TableDef.RefershLink when changing from odbc back to fs