Excel VBA via ADO connection

T

Terry

Hello!
I want to use Excel document connect Access database via ADO Connection.
I claim the following sentence in my program:
Dim conn As ADODB.Connection

It prompt the following error message while I compile my program:
User's type undefine

I lookup Excel's help for ADO Connection. It just pivottable connect Access
database via ADO Connection has been told. This help is no use for me.
Please tell how to use ADO Connection in Excel VBA. Thanks!
 
G

Guest

To use the ADO data types and procedures you first need to establish a
reference to the MS-ADO Library. This library contains all the "code" that
handles ADO connections for you.

In the VBA editor (alt-F11) go to Tools > References > tick the box next to
Microsoft Active Data Objects 2.x library.

If you've never used ADO connections in VBA or VB before I suggest that you
search the internet for a tutorial. I'm sure there's heaps out there.

- Rm
 
D

durex

How would one add this using VBA? Ive been searching around on how to
add a reference using VBA (which is how I came across this thread) but
havent been able to find out how...

Thanks a bunch.
 
G

Guest

Alright, I find it hard to believe that there isn't a tutorial on the net
that describes how to do this, but I'll write one on my train trip home
tonight. I'm not promising a great deal of detail but it should be enough to
get you started. Check back here tomorrow.

- Rm
 
D

durex

Robert said:
Alright, I find it hard to believe that there isn't a tutorial on the
net
that describes how to do this, but I'll write one on my train trip
home
tonight. I'm not promising a great deal of detail but it should be
enough to
get you started. Check back here tomorrow.

- Rm

There very well could be, but I scoured these forums, google web and
google group and couldnt find any definitive answer that actually
worked. Thanks a bunch.
 
D

durex

Ok.. so in researching this issue, pretty much everything Ive found
references something simliar to the following code to find the GUID of
the reference library I want to use:

Code:
--------------------

Sub Grab_Reference()
Dim myRef As Reference
On Error Resume Next
Set myRef = References(5)
If Not myRef Is Nothing Then
Debug.Print myRef.Name & vbLf & """" & myRef.Guid & """" & ", " & _
myRef.Major & ", " & myRef.Minor & vbLf & _
myRef.FullPath
End If
Set myRef = Nothing
End Sub

--------------------



... but for whatever reason when I run it (in Excel VBA) I get
"User-defined type not defined" which is referring to type
"reference".

Any ideas?
 
G

Guest

Just to let you know I have emailed an example of how to do an ADO
connection to to at the address on your profile. Let me know if you don't get
it.

If anyone else reads this I wil be puttnig it up on the web at some stage. I
don't have any web space at the moment but I'll look for some today and post
the link here when I have it.

- Rm
 
D

durex

I didnt get it... would you mind resending it to: tgraffam at gmail dot
com?

Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top