Reattach and Refresh SQL Links

You often need to reattach or refresh links in Microsoft Access. This code refreshes all currently linked tables to sync the attached tables with the server, then remove “dbo_” from all attached SQL Server tables. The two table Def loops allow you to re-sync tables after “dbo_” is removed:

 Dim tbDef As TableDefDim db As DatabaseDim strDBLocation As StringOn Error Resume NextCommonDialog1.ShowOpenstrDBLocation = CommonDialog1.FileNameIf strDBLocation = "" Then	EndEnd IfSet db = OpenDatabase(strDBLocation)For Each tbDef In db.TableDefs	' Refresh table links		db.TableDefs(tbDef.Name).RefreshLinkNext tbDefFor Each tbDef In db.TableDefs' Remove all dbo_'s from tablesIf Left(tbDef.Name, 4) = "dbo_" Then	tbDef.Name = Mid(tbDef.Name, 5, Len(tbDef.Name) - 4)End IfNext tbDef
Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

Recent Articles: