deadseasquirrels
Board Regular
- Joined
- Dec 30, 2004
- Messages
- 232
Some very gracious people have been helping me with trying to use VBA to hit an oracle database. I've gotten as far as this code below:
with very simple SQL scripts the above script works. But now the SQL string that is in there right now. I don't know what technology this is even, is this ADO? Whatever it is, I'd like to learn more, so that I can more properly debug the issues myself. For example right now I have no idea what
that whole section is about. If somebody can give me a hand, explain, or even point me to some documents that can explain I would greatly appreciate it. Thank you.
Code:
Private Sub SQLTest()
Dim dbsNDF As New ADODB.connection
Dim connString As String
Dim dbRS As Object
Dim sqlString As String
connString = "Provider=MSDAORA.1;Password=[pwd];User ID=[id];Data Source=DKARCH1.WORLD;Persist Security Info=True"
dbsNDF.connectionString = connString
dbsNDF.Open
sqlString = "Select SO.STUDENT.LAST_NAME FROM SO.STUDENT WHERE First_Name = 'Michelle' and LAST_NAME like 'De%'"
' Debug.Print MsgBox(sqlString)
' Stop
Set dbRS = dbsNDF.Execute(sqlString)
Cells(106, 1).CopyFromRecordset dbRS
If dbRS.EOF And dbRS.BOF Then
MsgBox "End of File"
GoTo CleanUpAndClose
Else
dbRS.MoveFirst
Do While Not dbRS.EOF
If dbRS.RecordCount = 0 Then
MsgBox ("empty")
End If
MsgBox (dbRS.Fields(1).Value)
dbRS.MoveNext
Loop
End If
CleanUpAndClose:
dbRS.Close
dbsNDF.Close
Set dbRS = Nothing
Set dbsNDF = Nothing
End Sub
Code:
If dbRS.EOF And dbRS.BOF Then
MsgBox "End of File"
GoTo CleanUpAndClose
Else
dbRS.MoveFirst
Do While Not dbRS.EOF
If dbRS.RecordCount = 0 Then
MsgBox ("empty")
End If
MsgBox (dbRS.Fields(1).Value)
dbRS.MoveNext
Loop
End If