title: VBA Code to Add Linked Table with Primary Key
body: <p>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.</p>
  
  <p><img src="https://i.stack.imgur.com/96GtK.png" alt="Dialog in the wizard to select unique identifier"></p>
  
  <p>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).</p>
  
  <p>I found several solutions, which are not applicable in my case:</p>
  
  <ul>
  <li>create the index after linking: I cannot for ODBC source</li>
  <li>create the primary key in database: I cannot, it's a view</li>
  </ul>
  
  <p>These would be applicable:</p>
  
  <ul>
  <li>a code which will do what the wizard does</li>
  <li>a code to relink without the need to delete TableDef and that works with ODBC linked table, and will not reset previously set identifier</li>
  </ul>
  
  <p>Temporary workaround:</p>
  
  <ul>
  <li>convert the view to materialized view and create unique index on it</li>
  </ul>