getrows only getting one row?

N

news

Can someone please tell me where I'm going wrong? I've used getrows
before without any problems, but today, it's just not playing ball (or
more likely I've just forgotten how to do this).


Dim rs As Recordset
Dim arr As Variant

Set rs = DBEngine(0)(0).OpenRecordset("SELECT fdPersonName from
tbPeople")
Debug.Print rs.RecordCount ' Returns 3 as expected
arr = rs.GetRows
Debug.Print UBound(arr, 2) + 1 ' Returns 1 instead of 3

A watch on arr shows an array with bounds of 0,0.
 
G

Guest

RecordCount is not valid unless you have loaded the
entire recordset by using movelast, or unless you are
using a table-type recordset.

(david)
 
D

Dirk Goldgar

Can someone please tell me where I'm going wrong? I've used getrows
before without any problems, but today, it's just not playing ball (or
more likely I've just forgotten how to do this).


Dim rs As Recordset
Dim arr As Variant

Set rs = DBEngine(0)(0).OpenRecordset("SELECT fdPersonName from
tbPeople")
Debug.Print rs.RecordCount ' Returns 3 as expected
arr = rs.GetRows
Debug.Print UBound(arr, 2) + 1 ' Returns 1 instead of 3

A watch on arr shows an array with bounds of 0,0.

Don't you have to pass the number of rows you want to retrieve? Maybe
that argument is defaulting to 1. Try:

With rs
If Not .EOF Then
.MoveLast
.MoveFirst
End If
arr = .GetRows(.RecordCount)
End With

or something along those lines.
 
N

news

david@epsomdotcomdotau said:
RecordCount is not valid unless you have loaded the
entire recordset by using movelast, or unless you are
using a table-type recordset.

(david)

But... recordcount is the one that's working, it's getrows() that
isn't.
 
G

Guest

But... recordcount is the one that's working, it's getrows() that
isn't.

really? what makes you think that? all the evidence you
have posted is that your (invalid) RecordCount returns a
different value than your (invalid) GetRows.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top