I have an updatable view in sql server database. When I create linked table to it with ODBC, I'm asked to select unique record identifier, in order for it to be updateable.
I need to dynamically relink this table in VBA, so I need to drop and recreate the linked table (I cannot update the TableDef.Connect property for ODBC table).
I found several solutions, which are not applicable in my case:
These would be applicable:
Temporary workaround:
In the File name text box, type the name of the source database or click Browse to display the File Open dialog box. Click Link to the data source by creating a linked table, and then click OK. The Link Tables dialog box opens. In the Link Tables dialog box, select the tables you want to link to.
Why can't you create an index for an ODBC source after linking?
At work, we are using Access with linked SQL Server tables, and when someone wants to connect to a different database (change from production environment to test environment), we do something like this for all tables:
Dim TD As TableDef
Dim ConString As String
ConString = "ODBC;DRIVER={SQL Server};SERVER=ServerName;DATABASE=DbName;Trusted_Connection=Yes;"
CurrentDb.TableDefs.Delete "SomeTable"
Set TD = CurrentDb.CreateTableDef("SomeTable", 0, "SomeTable", ConString)
CurrentDb.TableDefs.Append TD
Set TD = Nothing
CurrentDb.Execute "CREATE UNIQUE INDEX SomeIndex ON SomeTable (PrimaryKeyColumn) WITH PRIMARY"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With