How to programmatically create an ODBC Linked Table to a SQL Server View and have it be editable?

后端 未结 2 1756
悲&欢浪女
悲&欢浪女 2020-11-28 13:56

When I create a DSN connection to SQL Server using the wizard, I am able to link it to a view. In this case, Access recognizes it as an editable table.

But if I use

2条回答
  •  余生分开走
    2020-11-28 14:28

    Andre's answer is correct. I am using a little bit more complex code to create the index - it is just cosmetic change:

    Public Function RefreshIndexes()
        On Error Resume Next
        CurrentDb.Execute "CREATE UNIQUE INDEX [__uniqueindex] ON MyViewName (MyPrimaryKeyField) WITH PRIMARY;", dbFailOnError
        CurrentDb.Execute "CREATE UNIQUE INDEX [__uniqueindex] ON MyViewName2 (MyPrimaryKeyField2) WITH PRIMARY;", dbFailOnError
    End Function
    

    I call this command when user opens Access and only for views that do not have index.

提交回复
热议问题