afslaughter
05-11-2012, 03:56 PM
I want to link a table that has not been setup in the Linked Table Manager yet. This is probably real simple but I'm having a hard time figuring this out. I have looked at numerous examples from the forms and from Microsoft but it is over my head. I was hoping someone would be kind enough to explain this to a novice. This is what I have so far.
I have code to delete the table links that works fine:
DoCmd.DeleteObject acTable, "tblEquipment"
DoCmd.DeleteObject acTable, "tblUsers"
DoCmd.DeleteObject acTable, "tblShift"
And I have code to relink tables if they are already set up in the Linked Table Manager:
ReconnectMe:
Dim dbs As DAO.Database
Dim tdf As DAO.TableDef
Set dbs = CurrentDb()
MyPass = "Password"
MyPath = "C:\Some Folder\"
For Each tdf In dbs.TableDefs
If tdf.Connect <> "" Then
tdf.Connect = ";PWD=" & MyPass & ";Database=" & MyPath & "MTO.accdb"
tdf.RefreshLink
End If
Next
This is as far as I got on what I'm looking for:
Dim dbs As DAO.Database
Dim tdf As DAO.TableDef
MyPass = "Password"
MyPath = "C:\Some Folder\"
Set dbs = OpenDatabase(MyPath & "MTO.accdb", True, False, "MS Access;PWD=" & MyPass)
For Each tdf In dbs.TableDefs
Debug.Print " " & tdf.Name
If tdf.Connect <> "" Then
tdf.Connect = ";PWD=" & MyPass & ";Database=" & MyPath & "MTO.accdb"
tdf.RefreshLink
End If
Next
Doing a step by step of the code I see that all of the (tdf.Connect <>) don't meet the criteria to connect but I don't understand why.
Also if I manual force it to run the (tdf.Connect <>) line I get a run time error 3219 - Invalid Operation.
It would be really cool if some one can explain this to me. Thanks in advance.
I have code to delete the table links that works fine:
DoCmd.DeleteObject acTable, "tblEquipment"
DoCmd.DeleteObject acTable, "tblUsers"
DoCmd.DeleteObject acTable, "tblShift"
And I have code to relink tables if they are already set up in the Linked Table Manager:
ReconnectMe:
Dim dbs As DAO.Database
Dim tdf As DAO.TableDef
Set dbs = CurrentDb()
MyPass = "Password"
MyPath = "C:\Some Folder\"
For Each tdf In dbs.TableDefs
If tdf.Connect <> "" Then
tdf.Connect = ";PWD=" & MyPass & ";Database=" & MyPath & "MTO.accdb"
tdf.RefreshLink
End If
Next
This is as far as I got on what I'm looking for:
Dim dbs As DAO.Database
Dim tdf As DAO.TableDef
MyPass = "Password"
MyPath = "C:\Some Folder\"
Set dbs = OpenDatabase(MyPath & "MTO.accdb", True, False, "MS Access;PWD=" & MyPass)
For Each tdf In dbs.TableDefs
Debug.Print " " & tdf.Name
If tdf.Connect <> "" Then
tdf.Connect = ";PWD=" & MyPass & ";Database=" & MyPath & "MTO.accdb"
tdf.RefreshLink
End If
Next
Doing a step by step of the code I see that all of the (tdf.Connect <>) don't meet the criteria to connect but I don't understand why.
Also if I manual force it to run the (tdf.Connect <>) line I get a run time error 3219 - Invalid Operation.
It would be really cool if some one can explain this to me. Thanks in advance.