D
Dave
I wish to link an Access application to a SQLServer Database by VBA and have
managed to do this. The problem I have is that the linked tables are not
updateable. If I link to the same tables via the user interface (Tools>Link
Tables etc) they are.
I think the issue is that my code does not select a unique record identifier
for the table (which you are prompted to do in the user interface). Can I
do that in VBA.
Here is my code
Private Sub PopSqlServerTbls(strAccessTbl, strDBName, strTblName,
strDataSourceName, strUserID, strPword)
Dim cat As ADOX.Catalog
Dim tbl As ADOX.Table
Set cat = New ADOX.Catalog
cat.ActiveConnection = CurrentProject.Connection
Set tbl = New ADOX.Table
tbl.Name = strAccessTbl
Set tbl.ParentCatalog = cat
tbl.Properties("Jet OLEDB:Create Link") = True
tbl.Properties("Jet OLEDB:Link Provider String") = "ODBC" & ";DATABASE=" &
strDBName & ";UID=" & strUserID & ";PWD=" & strPword & ";DSN=" &
strDataSourceName
tbl.Properties("Jet OLEDB:Remote Table Name") = strTblName
cat.Tables.Append tbl
End Sub
managed to do this. The problem I have is that the linked tables are not
updateable. If I link to the same tables via the user interface (Tools>Link
Tables etc) they are.
I think the issue is that my code does not select a unique record identifier
for the table (which you are prompted to do in the user interface). Can I
do that in VBA.
Here is my code
Private Sub PopSqlServerTbls(strAccessTbl, strDBName, strTblName,
strDataSourceName, strUserID, strPword)
Dim cat As ADOX.Catalog
Dim tbl As ADOX.Table
Set cat = New ADOX.Catalog
cat.ActiveConnection = CurrentProject.Connection
Set tbl = New ADOX.Table
tbl.Name = strAccessTbl
Set tbl.ParentCatalog = cat
tbl.Properties("Jet OLEDB:Create Link") = True
tbl.Properties("Jet OLEDB:Link Provider String") = "ODBC" & ";DATABASE=" &
strDBName & ";UID=" & strUserID & ";PWD=" & strPword & ";DSN=" &
strDataSourceName
tbl.Properties("Jet OLEDB:Remote Table Name") = strTblName
cat.Tables.Append tbl
End Sub