View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Sam Wilson Sam Wilson is offline
external usenet poster
 
Posts: 523
Default Returning Data From ADO

Hi, I did lots of rooting around for this and eventually worked it out for
myself.

1. In your VB window go to tools/references and tick "Microsoft ActiveX Data
Objects 2.X Library"
2. The following code is then the basis for running a query:

Sub Demo()

Dim c As ADODB.Connection
Dim rs As ADODB.Recordset
Dim s As String

Set c = New ADODB.Connection
c.Open "Insert Connection String Here"

s = "SQL Select Statement of your choice"

Set rs = c.Execute(s, , 1)

do until rs.eof
'Do something with your results
rs.movenext
loop

rs.close

c.Close

End Sub

That should get you in the right direction - the online help for
adodb.recordsets has lots of help too.

Sam


"thefonz37" wrote:

Historically, I've built reports in Excel using Microsoft Query to grab data
off remote SQL servers and build various graphs and things. However, I was
getting a little frustrated with some of aspects of Microsoft Query, so I
started Googling and discovered that, with a little extra elbow grease, you
can pull data using something called ADO and not only can you make the SQL
cleaner, it apparently runs faster.

The problem I'm having is finding a decent tutorial to introduce this
concept. I keep finding blocks of VB code, but with no instruction about how
to fit this VB into spreadsheets. All I'm trying to do is mimic the
functionality of Microsoft Query really and I'm not having much luck.

Does anybody know any good resources that can explain this process a little
better?