Question : Link SQL Table using DSN or DSNless

having some problems with my database.  It is semi urgent.

I have an Access97 database and SQL 2000.   I'm trying to accomplish 1 or 2 things.  I would like to connect to the SQL database called "test" and link the "openord" table in there to the access db.  I do not want to setup an ODBC at every computer so I want to do it in a module.

Here is what I have so far but I'm getting errors.
____________________________________________________
Function CreateDSNConnection()
    On Error GoTo CreateDSNConnection_Err

   Dim stConnect As String
     stConnect = "Driver={SQL Server};Server=servername;Database=test;Uid=user;Pwd=password;"

DBEngine.RegisterDatabase "proddata", "SQL Server", True, stConnect

    CreateDSNConnection = True
    Exit Function

CreateDSNConnection_Err:

    CreateDSNConnection = False
    MsgBox "CreateDSNConnection encountered an unexpected error: " & Err.Description

End Function
__________________________________________________

That code right there gives me "ODBC Call failed".  But I know the username and password I'm trying works because I can create the DSN manually.  If I can manage to create the DSN, I'll manually link the table in SQL and use this code in the autoexec or something.


Now, here is the other way I'm trying to do it.
__________________________________
Function linktbl()

Dim DBconnect As Object
Dim CnnStr As String
Dim MyDb As Database
Dim tdf As TableDef

CnnStr = "Provider=sqloledb;" & _
"Data Source=servername;" & _
"Initial Catalog=test;" & _
"User ID=user;password=password;"

Set DBconnect = CreateObject("ADODB.Connection")
DBconnect.ConnectionString = CnnStr

Set MyDb = CurrentDb

Set tdf = MyDb.CreateTableDef("openord", dbAttachSavePWD, "openord", CnnStr)
MyDb.TableDefs.Append tdf
MyDb.TableDefs.Refresh

End Function
_____________________________________________

This code gets down to the "mydb.tabledefs.append" line and gives me an error "Couldn't find installable ISAM".

I'm lost and desperate at this point.  I have limited programming knowledge but willing to try anything.  I've been to many websites and looked at pages of code but don't imagine I need all of it to do something so simple.  Infact the code I posted here was taken from a few of those sites.  HELP! :)

Answer : Link SQL Table using DSN or DSNless

PAQed with points refunded (250)

Computer101
EE Admin
Random Solutions  
 
programming4us programming4us