I swear I had this code working earlier this morning but now every time it tries to link the external table I get prompted for a password even though the connection to the back end database is open. Anyone see where I'm going wrong?
Code:
Dim fs
Dim sSource
Dim db As Database
Dim tdf As TableDef
'On Error GoTo ERRHANDLER
Set fs = CreateObject("Scripting.filesystemobject")
sSource = CurrentProject.Path & IIf(Right(CurrentProject.Path, 1) <> "\", "\", "") & "Data.accdb"
If fs.FileExists(sSource) Then
Set db = OpenDatabase(sSource, False, False, "MS Access;pwd=" & fldPW & "")
For Each tdf In db.TableDefs
If Left(tdf.Name, 4) <> "MSys" Then
If DCount("[Name]", "Msysobjects", "[Name] = '" & tdf.Name & "'") = 1 Then
CurrentDb.Execute "DROP TABLE " & tdf.Name
End If
Debug.Print tdf.Name
DoCmd.TransferDatabase acLink, "Microsoft Access", sSource, acTable, tdf.Name, tdf.Name
End If
Next tdf
db.Close
Set db = Nothing
Else
MsgBox "This database expects the back end and the front end in the same folder" & vbCrLf & vbCrLf & "The back end database was not found", vbOKOnly, "ERROR Connecting to Back End"
Exit Sub
End If
Set fs = Nothing