Cheers all Experts,
I am currently using the following code to relink password protected BE to a FE, as the comments clearly say it will not work with multiple BE. How can the code be adjusted to work with multiple password protected BE?
I am currently using the following code to relink password protected BE to a FE, as the comments clearly say it will not work with multiple BE. How can the code be adjusted to work with multiple password protected BE?
Code:
Function RefreshLinks(MyDbName As String, pwd As String) As Boolean
' Refresh links to the supplied database. Return True if successful.
' Attempts to connect to mdb named in the jetdatapath setting
' Application fails if mdb not found
' This demo assumes that all the linked tabled appear in the same back end
' Code will need to be manipulated if using side ends.
' Also need to ensure that Miscrosoft DAO 3.6 Object library is referenced
'/Display message on status bar
DoCmd.Echo True, "Refreshing table links, please wait..."
Dim dbs As DAO.Database
Dim tdf As DAO.TableDef
'/Does the path exist
If Dir(MyDbName) = "" Then
MsgBox "Sorry, can't open the BE.", vbCritical, "Error"
End If
' Loop through all tables in the database.
Set dbs = CurrentDb
For Each tdf In dbs.TableDefs
' If the table has a connect string, it's a linked table.
If Len(tdf.Connect) > 0 Then
If tdf.Connect <> ";DATABASE=" & MyDbName & ";PWD=" & pwd Then
tdf.Connect = ";DATABASE=" & MyDbName & ";PWD=" & pwd
Err = 0
On Error Resume Next
tdf.RefreshLink ' Relink the table.
If Err <> 0 Then
RefreshLinks = False
MsgBox "Wrong Password!", vbExclamation, "Error"
Exit Function
End If
End If
End If
Next tdf
DoCmd.Echo True, "Done"
RefreshLinks = True ' Relinking complete.
End Function