I'm currently working with Excel VBA and SQL queries. I'm trying to take what I've put into my recordset and dump it into a two-dimensional array, so I can use the information in a later part of the function. The issue is that I only know two methods of extracting information from recordsets: CopyFromRecordset, and rs.Fields.
Here is the code I am attempting.
Dim ID_Array(150, 2) As String
Set rs = New ADODB.Recordset
Set oConn = New ADODB.Connection
strSql = "select id, name from groups"
rs.Open strSql, oConn
Do While Not rs.EOF
With ActiveSheet
For Index = 0 To 171
ID_Array(Index, 0) = CStr(rs.Fields(0).Value)
'Safety check to make sure the value isn't null (was having problems before)
If rs.Fields(1).Value <> Null Then
ID_Array(Index, 1) = CStr(rs.Fields(1).Value)
End If
rs.MoveNext
Next
End With
Loop
rs.Close
I'm positive I'm not assigning these values properly, since when I go to pull them from recordset, many are either wrong or not appearing (the name portion, particularly, will not even appear as a string on a MsgBox command, so I'm assuming it's not being assigned correctly).
Anyone have any experience with this? How to do I assign the id portion of rs to ID_Array's first dimension, and the name portion of rs to ID_Array's second dimension?