Hello everyone.
I made some more research but I'm stuck at an error.
Hope someone can help me out with this.
I have this code to relink a backend on startup.
I have a autoExec macro with the first comand run function open_template()
Code:
Function open_template()
Dim dbsTemp As Database
Dim strMenu As String
Dim strInput As String
' Open a Microsoft Jet database to which you will link
' a table.
Set dbsTemp = CurrentDb
' Call the ConnectOutput procedure. The third argument
' will be used as the Connect string, and the fourth
' argument will be used as the SourceTableName.
ConnectOutput dbsTemp, _
"Composite_Parts", _
";DATABASE=C:\Users\quico\Desktop\Weight_Estimate_Start_Template.accdb", _
"Composite_Parts"
ConnectOutput dbsTemp, _
"Deleted_Items", _
";DATABASE=C:\Users\quico\Desktop\Weight_Estimate_Start_Template.accdb", _
"Deleted_Items"
ConnectOutput dbsTemp, _
Material_List", _
";DATABASE=C:\Users\quico\Desktop\Weight_Estimate_Start_Template.accdb", _
"Material_List"
ConnectOutput dbsTemp, _
"Part_Category_List", _
";DATABASE=C:\Users\quico\Desktop\Weight_Estimate_Start_Template.accdb", _
"Part_Category_List"
ConnectOutput dbsTemp, _
"Part_Database", _
";DATABASE=C:\Users\quico\Desktop\Weight_Estimate_Start_Template.accdb", _
"Part_Database"
ConnectOutput dbsTemp, _
"Part_History", _
";DATABASE=C:\Users\quico\Desktop\Weight_Estimate_Start_Template.accdb", _
"Part_History"
ConnectOutput dbsTemp, _
"Project", _
";DATABASE=C:\Users\quico\Desktop\Weight_Estimate_Start_Template.accdb", _
"Project"
ConnectOutput dbsTemp, _
"Weight_Cat", _
";DATABASE=C:\Users\quico\Desktop\Weight_Estimate_Start_Template.accdb", _
"Weight_Cat"
ConnectOutput dbsTemp, _
"Weight_Locations", _
";DATABASE=C:\Users\quico\Desktop\Weight_Estimate_Start_Template.accdb", _
"Weight_Locations"
ConnectOutput dbsTemp, _
"Weights_Centers", _
";DATABASE=C:\Users\quico\Desktop\Weight_Estimate_Start_Template.accdb", _
"Weights_Centers"
End Function
Sub ConnectOutput(dbsTemp As Database, _
strTable As String, strConnect As String, _
strSourceTable As String)
Dim tdfLinked As TableDef
' Create a new TableDef, set its Connect and
' SourceTableName properties based on the passed
' arguments, and append it to the TableDefs collection.
Set tdfLinked = dbsTemp.CreateTableDef(strTable)
tdfLinked.Connect = strConnect
tdfLinked.SourceTableName = strSourceTable
dbsTemp.TableDefs.Append tdfLinked
End Sub
first question, is there a way to loop through the table names so I don't have to input them manually in the code?
I'm repeating this part of the code for every table:
Code:
ConnectOutput dbsTemp, _
"Part_Database", _
";DATABASE=C:\Users\quico\Desktop\Weight_Estimate_Start_Template.accdb", _
"Part_Database"
ConnectOutput dbsTemp, _
"Part_History", _
";DATABASE=C:\Users\quico\Desktop\Weight_Estimate_Start_Template.accdb", _
"Part_History"
and them I get an error saying the table already exists... should I delete all the tables at startup before running this code?
Thanks so much for all your help!