DSN-less connection to SQL Sever Linked Table

kbolick

Board Regular
Joined
Jun 4, 2002
Messages
137
I am using the code below. It will actually create the linked table, but I am unable to programatically specify the unique record id for the tables. Without this I am unable to edit the table's data. Any help would be appreciated.

Thanks.

Function LinkToDSNLess()
Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim strConnect As String


strConnect = "ODBC;DRIVER={SQL Server}" _
& ";SERVER=" & "MY_SERVER" _
& ";DATABASE=" & "MY_DATABASE" _
& ";UID=" & "my_user" _
& ";PWD=" & "mypassword" & ";"


Set db = CurrentDb()
Set tdf = db.CreateTableDef("dbo_Table1")

tdf.SourceTableName = "Table1"
tdf.Connect = strConnect

On Error Resume Next
db.TableDefs.Append tdf
db.TableDefs.Refresh


Set tdf = Nothing
Set db = Nothing

End Function
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Hi,

I'm not familiar with what you're asking. And I don't know what "the unique record id for the tables" is. I wonder if using ADOX might help. Can you explain please what the unique record id for the tables is?

regards, Fazza
 
Upvote 0

Forum statistics

Threads
1,221,498
Messages
6,160,160
Members
451,626
Latest member
dcobe

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top