Fluido
Below is some code which I hope will get you started! It connects to a
database, executes an SQL select statement and then loops through the
results returned.
If you wish to connect to your Oracle DB without having to first set
up an ODBC source, then please consult:
http://www.connectionstrings.com/
Regards,
Tim Jordan.
Option Explicit
Dim MyODBC
Dim MyUsername
Dim MyPassword
Dim strConn
Dim objADODBConn
Dim objRecordSet
Dim strSQL
Dim arrRecords
Dim intRowNum
Dim ThisCol1
Dim ThisCol2
Dim ThisCol3
MyODBC = "test"
MyUsername = "sa"
MyPassword = "m0nster"
Set objADODBConn = CreateObject("ADODB.Connection")
strConn="DSN=" & MyODBC & ";UID=" & MyUsername & ";PWD=" & MyPassword
& ";"
objADODBConn.Open(strConn)
Set objRecordSet=CreateObject("ADODB.RecordSet")
strSQL = "select Col1, Col2, Col3 from MyTable where Col1 = 'X';"
objRecordSet.Open strSQL,objADODBConn
If objRecordSet.EOF And objRecordSet.BOF Then
'No rows were selected
MsgBox "No Rows met the criteria"
Else
arrRecords=objRecordSet.GetRows
'arrRecords now contains the results from the select.
'we can step through each row and access each column of each row
like this
For intRowNum=0 to UBound(arrRecords,2)
ThisCol1 = arrRecords(0,intRowNum)
ThisCol2 = arrRecords(1,intRowNum)
ThisCol3 = arrRecords(2,intRowNum)
'Do something interesting with ThisCol1,ThisCol2,ThisCol3
MsgBox "Row " & intRowNum+1 & " of " _
& UBound(arrRecords,2)+1 & vbCrLf & "Col1 = " & _
ThisCol1 & ", Col2 = " & ThisCol2 & ", Col3 = " & ThisCol3
Next
End If
objRecordSet.Close
objADODBConn.Close
Set objRecordSet = Nothing
Set objADODBConn = Nothing