I am using VBA to query a MySQL database. This involves the use of the ODBC driver which I have up and running great.
I want to return the results of my query in a VBA multidimensional array. (columns for fields, rows for records)
There is a known problem with the ODBC MySQL driver in VBA in that the property .RecordCount evaluates to -1 rather than the actual number of records upon success. This means that I can't use it to size my array before looping through .EOF to extract the records.
I have tried this:
If Rs.RecordCount <> 0 Then //Just check if it's not false as recordcount is not fully functional
Fields = Rs.Fields.Count //This actually works
rw = 1
Dim result()
Do Until Rs.EOF
ReDim Preserve result(1 To rw, 1 To Fields)
C = 1
For Each MyField In Rs.Fields
result(rw, C) = MyField
C = C + 1
Next MyField
Rs.MoveNext
rw = rw + 1
Loop
get_result = result //Output the result
End if
But I get an error 9: subscript out of range. This is driving me nuts, in php this would be trivial but for some reason I can't figure this out in VBA. Any ideas?