Set dbs = CurrentDb
If bLive Then
sConn = sProdConn
Else
sConn = sDevConn
End If
'Simply updating the connection string doesn't seem to work.
'We apepar to have to remove it, then re-create it, easiest way is to pull all the tables into a local table and use that.
'z_DefTables is where they need to go.
'Call CreateListLinkedTables
Set rs = CurrentDb.OpenRecordset("Select ServerTable, LocalTable FROM z_DefTables")
For Each tbl In CurrentDb.TableDefs
If Len(tbl.Connect) > 0 Then
If Not InStr(1, tbl.Connect, "Excel") > 0 Then 'dont try and relink the excel objects
CurrentDb.TableDefs.Delete tbl.Name
i = i + 1
End If
End If
Next
Set tbl = Nothing
Debug.Print "Removed " & i & " linked tables"
i = 1
rs.MoveFirst
Do Until rs.EOF
DoEvents
Set td = dbs.CreateTableDef(rs!LocalTable, dbAttachSavePWD)
Debug.Print td.Name
td.Connect = sConn
td.SourceTableName = rs!ServerTable
dbs.TableDefs.Append td
td.RefreshLink
rs.MoveNext
i = i + 1
Loop
Debug.Print "Relinked " & i & " tables"
Set td = Nothing
Exit Sub
errorhand:
sErr = sErr & " " & Err.Number & " " & vbCrLf
Resume Next