Compartilhar via


Método TableDef.RefreshLink (DAO)

Aplica-se a: Access 365, Access 2021, Access 2019, Access 2016

Atualiza as informações de conexão para uma tabela vinculada (apenas espaços de trabalho do Microsoft Access).

Sintaxe

expressão . AtualizarLigação

expressão Uma variável que representa um objeto TableDef.

Comentários

Para alterar as informações de conexão para uma tabela vinculada, redefina a propriedade Connect do objeto TableDef correspondente e use o método RefreshLink para atualizar as informações. Utilizar o método RefreshLink não altera as propriedades da tabela vinculada nem os objetos Relation.

Para que essas informações de conexão existam em todas as coleções associadas ao objeto TableDef que representam a tabela vinculada, você deve usar o método Refresh em cada coleção.

A partir do Access 365 Versão 2403, o método RefreshLink preserva os índices de tabela existentes. Se anteriormente tivesse uma tabela ligada que perderia a chave primária depois de executar o método RefreshLink e adicionou código para recriar explicitamente o índice após a RefreshLink, isto resultará agora no erro 3283, "A chave primária já existe".

Exemplo

Este exemplo usa o método RefreshLink para atualizar os dados em uma tabela vinculada depois que sua conexão é alterada de uma fonte de dados para outra. O procedimento RefreshLinkOutput é exigido para que este procedimento seja executado.

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