Unable To Read From Recordset Into Arrays (1 Viewer)

iworkonline

Registered User.
Local time
Today, 04:19
Joined
May 25, 2010
Messages
44
Hi Guys

I need to read the stuff from the recordet into array. I have tried using GetRows method but it only reads one record. Here is how I am doing
Code:
    Dim myarray As Variant
    Dim ds As Dao.Recordset
    Set db = CurrentDb
    Set qdf = db.QueryDefs("Get_Distinct_Shippers")
    qdf.Parameters(0) = [Forms]![Form1]![Text3]
    Set ds = qdf.OpenRecordset
    myarray = ds.GetRows

Here is how I am extracting the values from the array
myarray(0,0).....

If I limit the results as following then I can read all the records
myarray = ds.GetRows(10)

But I do not want to limit the records.

Please help.
Thanks.
 

DCrake

Remembered
Local time
Today, 11:19
Joined
Jun 8, 2005
Messages
8,632
Here is how I would do it

Code:
Dim iRow as Interger
Dim iCol as Integer

Dim MyArray(x,y) ' Where x and y are the rows and cols

Dim Rs As DAO.RecordSet
Set Rs = CurrentDb.OpenRecordset("TblCustomers")

If Not Rs.EOF And Not Rs.BOF Then
   Do Until Rs.EOF
     For iCol = 0 To Rs.Fields.Count -1
        MyArray(iRow,iCol) = Rs(iCol)
     Next
     Rs.MoveNext
   Loop
   Rs.Close
End If
Set Rs = Nothing

Code untested and names for brevity only
 

iworkonline

Registered User.
Local time
Today, 04:19
Joined
May 25, 2010
Messages
44
Set qdf = db.QueryDefs("Get_Distinct_Shippers")
qdf.Parameters(0) = [Forms]![Form1]![Text3]
Set ds = qdf.OpenRecordset

ds.MoveLast
myarray = ds.GetRows(ds.RecordCount)
 

iworkonline

Registered User.
Local time
Today, 04:19
Joined
May 25, 2010
Messages
44
Code:
Set qdf = db.QueryDefs("Get_Distinct_Shippers")
qdf.Parameters(0) = [Forms]![Form1]![Text3]
Set ds = qdf.OpenRecordset
'I added the following line and works ok now 
ds.MoveLast
myarray = ds.GetRows(ds.RecordCount)

Thanks for the help.
 

vbaInet

AWF VIP
Local time
Today, 11:19
Joined
Jan 22, 2010
Messages
26,374
What does your last post actually mean? It's working? Finished piece of code?

By the way, your movelast will fill if there no records. You might want to check first using EOF and BOF.

Edit: Well I see you've added more info. :)
 

Users who are viewing this thread

Top Bottom