Link to home
Create AccountLog in
Avatar of Karen Schaefer
Karen SchaeferFlag for United States of America

asked on

DSN Less Connection to SQL table in Access

I am trying to connect to an SQL table in Access using DSNLess Connection string for Linked table.  Note multiple user will be access this database so setting ups a DSN connection for a linked table will not be sufficient.  What am I doing wrong:

Server name = SQL-NWSS-007\AUB1
Database name = FTVI_DBMS
SQL Table Name dbo.TA_AirplaneInfo

Public Function LinkODBCTable()

Dim db As Database, tdf As TableDef
Dim strConnect As String
strConnect = "ODBC;SERVER=MySQLServer;UID=sa;DRIVER=SQL" & _
"Server;DATABASE=SQL-NWSS-007\AUB1\FTVI_DBMS"
Set db = CurrentDb()
Set tdf = db.CreateTableDef(Name:="dbo_TA_AirplaneInfo", Attributes:=dbAttachSavePWD, SourceTableName:="dbo.TA_AirplaneInfo", Connect:=strConnect)
db.TableDefs.Append tdf

End Function

K
ASKER CERTIFIED SOLUTION
Avatar of Jim P.
Jim P.
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of Karen Schaefer

ASKER

Using my above mentioned server name and database name - how do I modify your code and do I still need to create the actual DSN in DATA Source Admin.?

Karen
I got it, however, how to I make sure the linked table is writable?  My  current linked table doesnot allow to add new records - WHY?

K
If you don't have an index/primary key(s) on the SQL Server tables, the tables, by default, will be read only. And after you do the index/PK, you will have to re-attach the table to get it to be an editable table.
Almost forgot:

Glad to be of assistance. May all your days get brighter and brighter.