Function RefreshTableLinks() As StringOn Error GoTo ErrHandlerDim strEnvironment As StringLet strEnvironment = GetEnvironmentDim db As DAO.DatabaseDim tdf As DAO.TableDefDim strCon As StringDim strBackEnd As StringDim strMsg As StringDim intErrorCount As IntegerSet db = CurrentDb'Loop through the TableDefs Collection.For Each tdf In db.TableDefs'Verify the table is a linked table.If Left$(tdf.Connect, 10) = ";DATABASE=" Then'Get the existing Connection String.Let strCon = Nz (tdf.Connect, "")'Get the name of the back-end database using String Functions.Let strBackEnd = Right$(strCon, (Len(strCon) - (InStrRev(strCon, "\") - 1)))If Len(strBackEnd & "") > 0 ThenSet tdf = db.TableDefs(tdf.Name)If strBackEnd = "\Common Shares_Data.mdb" Or strBackEnd = "\Adverse Events.mdb" Thentdf.Connect = ";DATABASE=" & strEnvironment & strBackEndElsetdf.Connect = ";DATABASE=" & CurrentProject.Path & strBackEndEnd Iftdf.RefreshLinkEnd IfEnd IfNext tdfErrHandler:If Err.Number <> 0 ThenMsgBox ("Error Number: " & Err.Number & vbCrLf & _"Error Description: " & Err.Description & vbCrLf)End IfEnd Function
Tags: VBA, Access, tables, link, relinking, database, tabelas, re-conectando,
Nenhum comentário:
Postar um comentário