PRMiller2
Technical User
- Jul 30, 2010
- 123
I am trying to create links to all tables in another database, but I do not know all of the table names. Following is the code that I am using successfully to link to tables for which I DO know the names:
I'm having some trouble finding the correct way to write this, and have run up against a wall. Any help would be greatly appreciated.
Thanks,
Paul
Code:
Function LinkDatabase(strTableName As String)
Dim db As DAO.Database
Dim strConnectionString As String
Dim tdf As DAO.TableDef
If DCount("*", "msysobjects", "Type = 4 AND name='" & strTableName & "'") = 0 Then
strConnectionString = "ODBC;Driver={SQL Server}; Database=dbname;Server=servername;" & _
" Trusted_Connection=Yes; UID=userid; "
Set db = CurrentDb
Set tdf = db.CreateTableDef(strTableName)
tdf.Connect = strConnectionString
tdf.SourceTableName = strTableName
db.TableDefs.Append tdf
Set tdf = Nothing
Set db = Nothing
End If
End Function
I'm having some trouble finding the correct way to write this, and have run up against a wall. Any help would be greatly appreciated.
Thanks,
Paul