Microsoft
Software
Hardware
Network
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=t
est;Uid=us
er;Pwd=pas
sword;"
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.Connec
tion")
DBconnect.ConnectionString
= CnnStr
Set MyDb = CurrentDb
Set tdf = MyDb.CreateTableDef("openo
rd", 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
Cisco ASA 5510 Rear Stencil
Filter, Add New Sheet, Delete All Sheets
excel macro find selected range to use within macro
SQL - Find records in one table not in another
Does CMap support multi-threading?
Expected user-defined type, not project
Togglelink
Mandatory Range of Cells in Excel
how do I reopen a closed company that was accidently closed in Microsoft Great Plains 10
Removing Hidden attribute from file