Hi,
I'm trying to change the table links to a password protected BE DB. I found an example online, which I adapted to my needs. When I set it up to fail to find the normal BE it seems to work as intended until it gets to the line "Tdf.RefreshLink". Then it crashes with a 3031 "Not a valid password" error. The code is:
I can't find any references or example to relinking a password protected table. Can anyone offer any examples or corrections to my code? I'm afraid I've reached an impass. :banghead:
I'm trying to change the table links to a password protected BE DB. I found an example online, which I adapted to my needs. When I set it up to fail to find the normal BE it seems to work as intended until it gets to the line "Tdf.RefreshLink". Then it crashes with a 3031 "Not a valid password" error. The code is:
Code:
Private Sub Form_Open(Cancel As Integer)
Dim Dbs As Database
Dim Tdf As TableDef
Dim Tdfs As TableDefs
Dim NewPathname As String
If Dir("\\OBBURTON-PC\Users\Public\Documents\" & _
"FUN Stuff\WilburBE.accdb") <> "" Then
MsgBox "File Founde!"
DoCmd.OpenForm "frmMain"
Forms!frmMain.RecordsetType = 1
DoCmd.Close acForm, "frmStart"
Else
'The following code came from:
'http://database.ittoolbox.com/groups/technical-functional/access-l/how-to-programme-the-linked-table-manager-using-vba-in-ms-access-5185870
'RelinkTables...Just as the name suggests, pass a path to a
'database eg RelinkTables("c:\windows\test.mdb")
'and it will go through all the tables in your
'database and link them to the new location
'Written by John Hawkins 20/9/99 www.fabalou.com
Set Dbs = CurrentDb
Set Tdfs = Dbs.TableDefs
Screen.MousePointer = 11
NewPathname = Environ("USERPROFILE") & "\Documents\" & _
"FUN Stuff\WilburBE.accdb"
'Loop through the tables collection
For Each Tdf In Tdfs
'If the table source is other than a base table
If Tdf.SourceTableName <> "" Then
'Set the new source
Tdf.Connect = ";DATABASE=" & NewPathname
Tdf.RefreshLink
End If
Next 'Goto next table
Screen.MousePointer = 0
MsgBox "All the application tables have been relinked " & _
"to the database at " & NewPathname & vbCrLf & _
" Thank you...", vbInformation, "Tables Reinked"
DoCmd.OpenForm "frmMain"
Forms!frmMain.RecordsetType = 3
End If
End Sub
Last edited: