Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Primary Key when linking in VB

Status
Not open for further replies.

Kubilus1

IS-IT--Management
Apr 25, 2001
99
US
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top