View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
John[_78_] John[_78_] is offline
external usenet poster
 
Posts: 87
Default Run a Database Query within VB

Thanks for the Reply. What exactly is the MDAC SDK? - looked it up on the MS
site would it be essential to have it?


"AA2e72E" wrote in message
...
It is quite simple. Here's an example:

Sub xx()
Cnn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\nwind.mdb"
Sql = "SELECT * FROM customers"
Set adors = CreateObject("ADODB.RecordSet")
adors.Open Sql, Cnn
While Not adors.EOF ' loop through
MsgBox adors.fields("CompanyName").Value ' see a value
adors.MoveNext 'Next Record
Wend
adors.Close ' End connection
End Sub


You should download the MDAC SDK from Microsoft (its free): this contains

the documentation for ADO, which you would need.