Bjornson15
Technical User
I have been trying to do this for sometime now. I have code that "works" but it takes too long to come back.
I am trying to download a Access query into an array. I cannot take less data than what I am grabbing.
Here is my code:
Function GET_ACCESS_DATA(SQLSTRING As String)
Dim QD As QueryDef, RS As Recordset, RCD As Long
Dim i As Long, j As Long
Dim INFO, DT() As Variant
Set QD = DB.CreateQueryDef("", SQLSTRING)
Set RS = QD.OpenRecordset()
On Error GoTo NO_DATA
RS.MoveLast
RCD = RS.RecordCount
RS.MoveFirst
INFO = RS.GetRows(RCD)
ReDim DT(UBound(INFO, 2) + 1, UBound(INFO, 1) + 1)
For i = 1 To UBound(INFO, 1) + 1
For j = 1 To UBound(INFO, 2) + 1
DT(j, i) = INFO(i - 1, j - 1)
Next j
Next i
GET_ACCESS_DATA = DT
Exit Function
NO_DATA:
ReDim DT(1, 1)
DT(1, 1) = "NO DATA"
GET_ACCESS_DATA = DT
End Function
I connect to the database before this point (this does not slow anything down).
The issue is: INFO = RS.GetRows(RCD)
It just takes too long to "load" the data. Is there any other code that can bring back the data quicker? (It takes this line of code about 3-5 mins to "load" for appro 50,000 rows of data) The table is indexed properly.
Can I work with the recordset the same as an array?
Thanks for any advise you may have. I will be more than willing to get more specific if need be.
Tom
I am trying to download a Access query into an array. I cannot take less data than what I am grabbing.
Here is my code:
Function GET_ACCESS_DATA(SQLSTRING As String)
Dim QD As QueryDef, RS As Recordset, RCD As Long
Dim i As Long, j As Long
Dim INFO, DT() As Variant
Set QD = DB.CreateQueryDef("", SQLSTRING)
Set RS = QD.OpenRecordset()
On Error GoTo NO_DATA
RS.MoveLast
RCD = RS.RecordCount
RS.MoveFirst
INFO = RS.GetRows(RCD)
ReDim DT(UBound(INFO, 2) + 1, UBound(INFO, 1) + 1)
For i = 1 To UBound(INFO, 1) + 1
For j = 1 To UBound(INFO, 2) + 1
DT(j, i) = INFO(i - 1, j - 1)
Next j
Next i
GET_ACCESS_DATA = DT
Exit Function
NO_DATA:
ReDim DT(1, 1)
DT(1, 1) = "NO DATA"
GET_ACCESS_DATA = DT
End Function
I connect to the database before this point (this does not slow anything down).
The issue is: INFO = RS.GetRows(RCD)
It just takes too long to "load" the data. Is there any other code that can bring back the data quicker? (It takes this line of code about 3-5 mins to "load" for appro 50,000 rows of data) The table is indexed properly.
Can I work with the recordset the same as an array?
Thanks for any advise you may have. I will be more than willing to get more specific if need be.
Tom