VBA Code to Add Linked Table with Primary Key VBA Code to Add Linked Table with Primary Key vba vba

VBA Code to Add Linked Table with Primary Key


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 TableDefDim ConString As StringConString = "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 TDSet TD = NothingCurrentDb.Execute "CREATE UNIQUE INDEX SomeIndex ON SomeTable (PrimaryKeyColumn) WITH PRIMARY"