Hi EE
I have the following code to re-link data
Dim strPathBE As String
Dim tdf As TableDef
With FileDialog(msoFileDialogFilePicker)
If Not .Show Then Exit Sub
strPathBE = .SelectedItems(1)
End With
With CurrentDb
For Each tdf In .TableDefs
If tdf.Attributes And dbSystemObject Then
ElseIf Len(tdf.Connect) = 0 Then
ElseIf Left(tdf.Connect, 1) <> ";" Then
Else
tdf.Connect = ";DATABASE=" & strPathBE
tdf.RefreshLink
End If
Next tdf
Me!txtLoc = strPathBE
End With
It works if data has no password. I assume it needs some extra code to handle password.
something at the end of this line perhaps
tdf.Connect = ";DATABASE=" & strPathBE (Password)
Any help appreciated
chestera
Microsoft Access
Last Comment
chestera
8/22/2022 - Mon
Rey Obrero (Capricorn1)
first open the BE
Dim strPathBE As String
Dim tdf As TableDef
dim strPwd As String
dim dbBE as Dao.database
strPwd="yourPassword"
With FileDialog(msoFileDialogFilePicker)
If Not .Show Then Exit Sub
strPathBE = .SelectedItems(1)
End With
'open the back end
Set dbBE = DBEngine(0).OpenDatabase(strPathBE, False, True, ";pwd=" & strPwd)
with dbBE
For Each tdf In .TableDefs
tdf.Connect = ";Database=" & strPathBE & ";PWD=" & strPwd
next
end with
Rey Obrero (Capricorn1)
oops, use this
with currentdb
For Each tdf In .TableDefs
tdf.Connect = ";Database=" & strPathBE & ";PWD=" & strPwd
next
end with
chestera
ASKER
Rey Obrero
Getting Invalid Operation tdf Connect line
Dim strPathBE As String
Dim tdf As TableDef
Dim strPwd As String
Dim dbBE As DAO.Database
strPwd = "ep2015ms"
With FileDialog(msoFileDialogFilePicker)
If Not .Show Then Exit Sub
strPathBE = .SelectedItems(1)
End With
With CurrentDb
For Each tdf In .TableDefs
tdf.Connect = ";Database=" & strPathBE & ";PWD=" & strPwd
Next
End With
With CurrentDb
For Each tdf In .TableDefs
If tdf.Attributes And dbSystemObject Then
ElseIf Len(tdf.Connect) = 0 Then
ElseIf Left(tdf.Connect, 1) <> ";" Then
Else
tdf.Connect = ";Database=" & strPathBE & ";PWD=" & strPwd
tdf.RefreshLink
End If
Next tdf
Me!txtLoc = strPathBE
End With
chestera
ASKER
Rey Obrero
This is what I now have. Still getting error message last line Object variable etc. If I leave the last two lines out there is no error but it wont link to the data.
Dim strPathBE As String
Dim tdf As TableDef
Dim strPwd As String
Dim dbBE As DAO.Database
strPwd = "ep2015ms"
With FileDialog(msoFileDialogFilePicker)
If Not .Show Then Exit Sub
strPathBE = .SelectedItems(1)
End With
With CurrentDb
For Each tdf In .TableDefs
If tdf.Attributes And dbSystemObject Then
ElseIf Len(tdf.Connect) = 0 Then
ElseIf Left(tdf.Connect, 1) <> ";" Then
Else
tdf.Connect = ";DATABASE=" & strPathBE & ";PWD=" & strPwd
tdf.RefreshLink
End If
Next tdf
End With
'open the back end
Set dbBE = DBEngine(0).OpenDatabase(strPathBE, False, True, ";pwd=" & strPwd)
Dim strPathBE As String
Dim tdf As TableDef
dim strPwd As String
dim dbBE as Dao.database
strPwd="yourPassword"
With FileDialog(msoFileDialogFi
If Not .Show Then Exit Sub
strPathBE = .SelectedItems(1)
End With
'open the back end
Set dbBE = DBEngine(0).OpenDatabase(s
'Set Connect property
tdf.Connect = ";Database=" & strPathBE & ";PWD=" & strPwd