Thread: ODBC Connection
View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Rob Bovey Rob Bovey is offline
external usenet poster
 
Posts: 811
Default ODBC Connection

Hi Adrian,

The code below is using objects from the Microsoft DAO 3.X Object
Library. If you also have the Microsoft ActiveX Data Objects 2.X Library
(ADO) referenced you will have a collision on your Connection object,
because both of these object libraries contain a connection object.

The easiest way to solve this is to remove the reference to the ADO
object library. You could also fully qualify your object variable
declarations like so:

Dim wrkODBC As DAO.Workspace
Dim conData As DAO.Connection

and it would remove the ambiguity.

--
Rob Bovey, Excel MVP
Application Professionals
http://www.appspro.com/

* Please post all replies to this newsgroup *
* Unsolicited e-mail replies will be ignored *


"Adrian T" wrote in message
...
Hello:


This is something I have never done before. I am trying to have an open
connection with a SQL database registered in my machine's ODBC driver.
Here's
my code

Private Sub Connect()

Dim wrkODBC As Workspace
Dim conData As Connection

Set wrkODBC = CreateWorkspace("NewODBCWorkspace", "admin", "", dbUseODBC)

Set conData = wrkODBC.OpenConnection("Connection1", , ,
"ODBC;DATABASE=Sale;UID=sa;PWD=sa;DSN=SQL_SERV ER")

End Sub


When I run the code, an error msg says "Run-time Error:13 (Type
Mismatch)".
I am almost convinced that it has something to do with referencing to the
right library. Does anyone know how to fix this?


Thanks!