Link to home
Start Free TrialLog in
Avatar of bill201
bill201

asked on

Changing linked table location (that protected with a password) programatically on acccess 2013

hi

how can i with vba relink a table to database that closed with password. for example i have this code  
 For Each td In TDS
        If td.Connect = ";DATABASE=" & OldPathName Then
            td.Connect = ";DATABASE=" & NewPathName, passowrd:mypassword'
            td.RefreshLink 'Refresh the link

Open in new window

Avatar of Sheils
Sheils
Flag of Australia image

Try this

Public Function FixTableLink()
 
Dim db As Database
Dim strPath As String
Dim strConnect As String
 
strPath = "NewPathName"

 
strConnect = ";DATABASE=" & strPath & "; password:mypassword"
 
Set db = CurrentDb
 
For Each tbl In db.TableDefs
 
    If Nz(DLookup("Type", "MSysObjects", "Name = '" & tbl.name & "'"), 0) = 6 And tbl.Connect <> strConnect Then
         
        tbl.Connect = strConnect
        tbl.RefreshLink
         
    End If
 
Next tbl
 
End Function
ASKER CERTIFIED SOLUTION
Avatar of Sheils
Sheils
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial