Allen said:
Set the Connect property of the TableDef.
Don't forget to RefreshLink as well.
Ok. This works.
The only question I have now is this works with a current opened database
and links into it. How do you link from another database to another
database?
The Set dbsTemp = CurrentDb must be what needs to be changed to the path to
the other database.
I tried Set dbsTemp = "C:\folder\MyDatabase.mdb"
But it didn't work. Can it be done?
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, _
"LinkedTable", _
";DATABASE=C:\db1.mdb", _
"Dates"
End Sub
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