I need to do the following in VB code. Link a SQL view to access as a table, and set a primary key for the linked table so the data will be updatable. Currently I have the following:
Public Function setSpecificTableLink
(objectNameP As String, databaseNameP As String) As Boolean
Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim qdf As DAO.QueryDef
Dim connectString As String
setSpecificTableLink = False
connectString = "Driver={SQL Server}; " & _
"Server=NTSERVER;" & _
"UID=;PWD=;WSID=;" & _
"Database=" & databaseNameP & ";" & _
"Table=dbo." & objectNameP
Set db = DBEngine(0)(0)
For Each tdf In db.TableDefs
If (Len(tdf.Connect) > 0) And _
tdf.Name = objectNameP Then
tdf.Connect = connectString
setSpecificTableLink = True
tdf.RefreshLink
objectFound = True
End If
Next
db.TableDefs.Refresh
End Function
This code will refresh the link, but if I'm linking to a view, the primary key is dropped and the object is no longer updatable. Any ideas?
Thanks a lot,
Matt
Public Function setSpecificTableLink
(objectNameP As String, databaseNameP As String) As Boolean
Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim qdf As DAO.QueryDef
Dim connectString As String
setSpecificTableLink = False
connectString = "Driver={SQL Server}; " & _
"Server=NTSERVER;" & _
"UID=;PWD=;WSID=;" & _
"Database=" & databaseNameP & ";" & _
"Table=dbo." & objectNameP
Set db = DBEngine(0)(0)
For Each tdf In db.TableDefs
If (Len(tdf.Connect) > 0) And _
tdf.Name = objectNameP Then
tdf.Connect = connectString
setSpecificTableLink = True
tdf.RefreshLink
objectFound = True
End If
Next
db.TableDefs.Refresh
End Function
This code will refresh the link, but if I'm linking to a view, the primary key is dropped and the object is no longer updatable. Any ideas?
Thanks a lot,
Matt