Linked table ms access 2010 change connection string
To print all connection strings:
Dim tdf As TableDef
Dim db As Database
Set db = CurrentDb
For Each tdf In CurrentDb.TableDefs
If tdf.Connect <> vbNullString Then
Debug.Print tdf.Name; " -- "; tdf.SourceTableName; " -- "; tdf.Connect
End If
Next
To create a linked table:
With CurrentDb
''If the table does not have a unique index, you will need to create one
''if you wish to update.
Set tdf = .CreateTableDef("LocalName")
tdf.Connect = "ODBC;DRIVER=SQL Server;SERVER=10.0.0.1;" _
& "UID=testdb;APP=Microsoft Office 2003;WSID=abc;TABLE=dbo.user"
tdf.SourceTableName = "TABLE_NAME"
.TableDefs.Append tdf
.TableDefs.Refresh
End With
To change a link:
Set db = CurrentDB
Set tdf = db.TableDefs("MyTable")
tdf.Connect = "ODBC;DRIVER=SQL Server;SERVER=10.0.0.1;" _
& "UID=testdb;APP=Microsoft Office 2003;WSID=abc;TABLE=dbo.user"
tdf.RefreshLink
You can change the connection string using the following guide (Original Source).
Firstly, get the existing connection string.
- Open MS Access
- Right mouse click on a table that used to work or you are sure does work and choose “Design View”.
- Select Yes on the warning screen to continue
- If, on the right, there is no properties window for the table, on the Ribbon (Access 2010) click Property Sheet
- This reveals a Description property – copy all that it is in that property it and paste it into Notepad or somewhere for later.
Secondly update the connection string.
- Click the External Data in the ribbon and choose ‘Linked Table Manager’
- Click the Always prompt for a new location check box – this is a complicated way to ask the user if (s)he wasts to change the connection info
- Click Select All button or choose the tables you wish to update with check marks
- Click OK
- A dialog comes up. Click New
- Choose SQL Server as your driver
- Click the Advanced Button
- Paste all that stuff in Notepad
- EXCEPT REMOVE the TABLE=… stuff up to the next semicolon.
- Change the server name
- Click OK
- It then prompts you to save all this into a file for later. Chooose a spot in My Documents in a connections folder – or better yet on a network location for other’s to use later
- Click OK a couple of times
- Now Access will replace all your tables with the new DSN (connection details) string.