Thank you. I ended up modifying some code to reference a Table contained on the Front End of the Database that passes the Pathway of the Linked Table on start-up. I'm sure it could be done better. I would like to modify it to not refresh the links if the links don't need to be refreshed testing the users Front End links against a table that is populated after initial Start-Up (We are having issues with the Split Database not being as responsive when people are working remotely.
Here it is:
Here it is:
Code:
Sub RelinkTablesToAccess()
Dim rst As DAO.Recordset
Dim intNumTables As Integer
Dim varReturn As Variant
Dim intI As Integer
Dim tdf As TableDef
Dim fd As Office.FileDialog
Dim vrtSelectedItem As Variant
Dim sFileName As String
Dim tableName As String
On Error Resume Next
Set rst = CurrentDb.OpenRecordset("AcctExec", dbOpenDynaset)
'check for failure - the link must be bad.
If Err <> 0 Then
'get the new location
' Set fd = Application.FileDialog(msoFileDialogFilePicker)
' fd.Title = "Please select the backend database"
' fd.Filters.Clear
' fd.Filters.Add "Access Databases", "*.mdb"
' If fd.Show = True Then
' For Each vrtSelectedItem In fd.SelectedItems
' sFileName = vrtSelectedItem
' Next
' End If
'Rebuild the links. Check for the number of tables first
intNumTables = CurrentDb.TableDefs.Count
varReturn = SysCmd(acSysCmdInitMeter, "Relinking tables", intNumTables)
'Loop through all tables. Reattach those with nonzero-length Connect strings
intI = 0
For Each tdf In CurrentDb.TableDefs
'if connect is blank, it's not a linked table
If Len(tdf.Connect) > 0 Then
intI = intI + 1
CurrentDb.TableDefs.Delete tdf.name
tableName = tdf.name
sFileName = Linked_Table_Approach(tableName)
' MsgBox "Table Name = " & tableName & " File Path = " & sFileName
Set tdf = CurrentDb.CreateTableDef(tableName)
tdf.Connect = ";DATABASE=" & sFileName
tdf.SourceTableName = tableName
tdf.RefreshLink
CurrentDb.TableDefs.Append tdf
End If
'Don't do anything
varReturn = SysCmd(acSysCmdUpdateMeter, intI)
Next tdf
'Don't do anything
varReturn = SysCmd(acSysCmdRemoveMeter)
End If
End Sub
Code:
'This code reads from a Table that has the list of Tables that need to be relinked and their respective Paths
Public Function Linked_Table_Approach(xTable_Name As String)
Dim db As DAO.Database
Dim rs As Recordset
Dim strSQL As String
Dim xPath As String
Dim xFlag As Boolean
xFlag = False
xPath = ""
Set db = CurrentDb
strSQL = "SELECT * FROM [Linked Tables]"
Set rs = db.OpenRecordset(strSQL)
Do While (Not rs.EOF And Not xFlag)
If xTable_Name = rs!Linked_Table Then
xPath = rs!Absolute_Path
xFlag = True
Linked_Table_Approach = xPath
rs.Close
Set rs = Nothing
db.Close
Linked_Table_Approach_Exit:
Exit Function
Else
rs.MoveNext
End If
Loop
rs.Close
Set rs = Nothing
db.Close
'Need to have something that returns a negative value
Linked_Table_Approach = "Table not found"
End Function
Comment