Reputation: 149
I have an access program that I am using that needs to access some data on our PostgreSQL server. The problem I am having is that the link is being created read-only. If I use the menu items in access to create the links, then it works fine. My end users will be using the runtime access so do not have access to the menu.
Here is the code that is doing the linking:
Sub createLinkedTable_PostgreSQL(PostgreSQL_tableName As String)
Dim cdb As DAO.Database, tbd As DAO.TableDef
Set cdb = CurrentDb
Set tbd = New DAO.TableDef
tbd.Connect = "ODBC;Driver={PostgreSQL ANSI};Server=10.10.10.200;Port=5432;Database=BIO-Static;" & _
"UID=UserID;PWD=Password;"
tbd.SourceTableName = PostgreSQL_tableName
tbd.Name = Replace(PostgreSQL_tableName, ".", "_", 1, -1, vbTextCompare)
' e.g. "public.table1"->"public_table1"
cdb.TableDefs.Append tbd
Set tbd = Nothing
Set cdb = Nothing
End Sub
How do I get this to open the table in an update mode?
Upvotes: 2
Views: 403
Reputation: 123779
When creating an ODBC linked table, Access will use the primary key from the remote table if it has one. However, if
then the ODBC linked table will have no primary key. In that case you will be able to read from the ODBC linked table but you will not be able to update it.
The possible solutions are:
CREATE UNIQUE INDEX ...
to give it a primary key, as explained in the related answer hereUpvotes: 1