I am using ADO to query SQL Server and the result set that is returned I want to store in an arry. Should be pretty straight-forward, but for some reason, my count returns a -1? This is my syntax, what should I change in order to have the results store in the array? If I run my syntax directly against my SQL Server installation, there are 8 rows returned. What do I need to alter in order for the accurate data to be stored in the array?
Code:
Public Function PrintIT()
Dim c As ADODB.Connection
Dim r As ADODB.Recordset
Dim f As ADODB.Field
Dim i As Integer
Dim conn As String
Dim arrResults() As Variant
Dim pth As Variant
Set c = New ADODB.Connection
Dim accapp As Access.Application
Set accapp = New Access.Application
With c
.Provider = "sqloledb.1"
With .Properties
.Item("Data Source") = "Server"
.Item("Initial Catalog") = "database"
.Item("PassWord") = "password"
.Item("User ID") = "userid"
End With
.Open
Set r = c.Execute("SELECT DISTINCT(redlight) FROM [Database].[dbo].[Table]")
i = 0
r.MoveFirst
Do Until r.EOF
arrResults(i) = r.Fields(0)
i = i + 1
Loop
r.Close
Set rst = Nothing
c.Close
For Each pth In arrResults
Debug.Print (pth)
Next pth
End With
End Function