Quote:
|
quote:Having said that, I am sure you know what you are doing...
|
Yikes Roly! Good to know at least one of us is ;)!
Nope, you don't need to delete the links. I was just thinking it would be easier to refresh them at startup. Access won't auomatically reflect any underlying table structure changes you make on SQL Server, so if you change table structures or add new user tables, you'll have to manually refresh the existing links or create new ones. But then you probably already knew that. Also, there may be some user tables on SQL Server that you don't want to establish links for.
To establish the links manually on a table-by-table basis, you could just use Warren's AttachTable_ClientServer function.
Just for the heck of it though, here's a bare bones Linking routine that includes all you need to establish a new link, and then leave it alone forever. Just supply the name of the remote table, and the name you want to use for the local table. I'm just connecting to the Sql Server Northwind db on my local system.
Sub CreateLinkedSQLServerTable(strLocalTableName As String, strRemoteTableName)
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 = strLocalTableName
Set tbl.ParentCatalog = cat
tbl.Properties("Jet OLEDB:Link Provider String") = _
"ODBC" & _
";Driver=SQL Server" & _
";Server=(local)" & _
";Database=Northwind" & _
";UID=sa" & _
";pwd=myPassword"
tbl.Properties("Jet OLEDB:Remote Table Name") = strRemoteTableName
tbl.Properties("Jet OLEDB:Create Link") = True
cat.Tables.Append tbl
Set cat = Nothing
Application.RefreshDatabaseWindow
End Sub
Call the sub with something like:
CreateLinkedSQLServerTable "Customers", "dbo.Customers"
Don't know if you've run code from the VBA Editor before but its really easy. Just create a new standard module, paste the above routine into it, open the Immediate Window by pressing Ctrl-G, type the procedure call in the immediate Window, place your cursor at the end of the procedure call, and hit enter.
HTH,
Bob