I have the code which can successfully pull data from database, but my question is related to something else.
I do NOT want to copy data to sheet Test, for two reasons:
1) The return query data may have many records (exceeding maximum excel 2013 row limitation 1,048,576), which will cause the code bug
2) I will need further process the data, it is very time consuming to loop through excel data.
So I am thinking about sorting data in memory, processing data in memory should be much faster than processing data in spreadsheet. I will copy final data (after being processed) into spreadsheet. That being said, I do NOT want this line of code (ThisWorkbook.Sheets("Test").Cells(7, 5).CopyFromRecordset CVRs) at this point, I want to sort the data into an dynamic array, since I don't know how many records from CVRs.
Maybe I need a line to code to count the number of returned records? If the number of records is k, then
Dim DynArrayField1 (0 To k-1) As Long
Dim DynArrayField2 (0 To k-1) As Long
Dim DynArrayField3 (0 To k-1) As Long
//Assume there are 3 fields in returned query records
How to count the number of record? How to store the records into the arrays?
Thanks.
Dim CVRs As ADODB.Recordset
Dim CVQuery As String
Dim CVField As Field
.....................
CVQuery = "Select Field1, Field2, Field3 From Tablename Where ....."
CVRs.Open CVQuery, Cn
ThisWorkbook.Sheets("Test").Cells(7, 5).CopyFromRecordset CVRs
Bookmarks