VBA Code to Add Linked Table with Primary Key

后端 未结 1 1022
南笙
南笙 2020-12-18 03:19

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.

相关标签:
1条回答
  • 2020-12-18 03:32

    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"
    
    0 讨论(0)
提交回复
热议问题