Embedding a Database Password in Code
Sub LinkToSecured()
Dim cat As ADOX.Catalog
Dim tbl As ADOX.Table
Set cat = New ADOX.Catalog
cat.ActiveConnection = CurrentProject.Connection
Set tbl = New ADOX.Table
tbl.Name = "tblLinkedTable"
Set tbl.ParentCatalog = cat
tbl.Properties("Jet OLEDB:Create Link") = True
tbl.Properties("Jet OLEDB:Link Provider String") = "ODBC" & _
";DATABASE=Pubs" & _
";UID=SA" & _
";PWD=" & _
";DSN=PublisherData"
tbl.Properties("Jet OLEDB:Remote Table Name") = "Employees"
cat.Tables.Append tbl
End Sub
Related examples in the same category