Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Applies to: Access 365, Access 2021, Access 2019, Access 2016
Updates the connection information for a linked table (Microsoft Access workspaces only).
Syntax
expression .RefreshLink
expression A variable that represents a TableDef object.
Remarks
To change the connection information for a linked table, reset the Connect property of the corresponding TableDef object and then use the RefreshLink method to update the information. Using RefreshLink method doesn't change the linked table's properties and Relation objects.
For this connection information to exist in all collections associated with the TableDef object that represents the linked table, you must use the Refresh method on each collection.
Starting with Access 365 Version 2403, the RefreshLink method preserves existing table indexes. If you previously had a linked table that would lose the primary key after running the RefreshLink method and you added code to explicitly recreate the index after the RefreshLink, this will now result in error 3283, “Primary key already exists”.
Example
This example uses the RefreshLink method to refresh the data in a linked table after its connection has been changed from one data source to another. The RefreshLinkOutput procedure is required for this procedure to run.
Sub RefreshLinkX()
Dim dbsCurrent As Database
Dim tdfLinked As TableDef
' Open a database to which a linked table can be
' appended.
Set dbsCurrent = OpenDatabase("DB1.mdb")
' Create a linked table that points to a Microsoft
' SQL Server database.
Set tdfLinked = _
dbsCurrent.CreateTableDef("AuthorsTable")
' Note: The DSN referenced below must be configured to
' use Microsoft Windows NT Authentication Mode to
' authorize user access to the Microsoft SQL Server.
tdfLinked.Connect = _
"ODBC;DATABASE=pubs;DSN=Publishers"
tdfLinked.SourceTableName = "authors"
dbsCurrent.TableDefs.Append tdfLinked
' Display contents of linked table.
Debug.Print _
"Data from linked table connected to first source:"
RefreshLinkOutput dbsCurrent
' Change connection information for linked table and
' refresh the connection in order to make the new data
' available.
' Note: The DSN referenced below must be configured to
' use Microsoft Windows NT Authentication Mode to
' authorize user access to the Microsoft SQL Server.
tdfLinked.Connect = _
"ODBC;DATABASE=pubs;DSN=NewPublishers"
tdfLinked.RefreshLink
' Display contents of linked table.
Debug.Print _
"Data from linked table connected to second source:"
RefreshLinkOutput dbsCurrent
' Delete linked table because this is a demonstration.
dbsCurrent.TableDefs.Delete tdfLinked.Name
dbsCurrent.Close
End Sub
Sub RefreshLinkOutput(dbsTemp As Database)
Dim rstRemote As Recordset
Dim intCount As Integer
' Open linked table.
Set rstRemote = _
dbsTemp.OpenRecordset("AuthorsTable")
intCount = 0
' Enumerate Recordset object, but stop at 50 records.
With rstRemote
Do While Not .EOF And intCount < 50
Debug.Print , .Fields(0), .Fields(1)
intCount = intCount + 1
.MoveNext
Loop
If Not .EOF Then Debug.Print , "[more records]"
.Close
End With
End Sub