Fordraiders
asked on
vba getting proper uboundin an array
access vba 2010
After i get a recordset count
I'm trying to put the items into an array.
The array keeps coming up with only one item.
even though i have 10 records ?
Thanks
fordraiders
After i get a recordset count
I'm trying to put the items into an array.
The array keeps coming up with only one item.
even though i have 10 records ?
' put the items into an array for emailing each row.
dArrp = rs1.GetRows()
' just in case i need it
d = rs1.RecordCount
lngCount = UBound(dArrp, 2) + 1
For i = LBound(dArrp, 2) To UBound(dArrp, 2) ' my ubound always ends up being "one"
Thanks
fordraiders
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
GetRows need to know how many records to pull. Thus, to get all records:
rs1.MoveLast
rs1.MoveFirst
dArrp = rs1.GetRows(rs.RecordCount)
lngCount = UBound(dArrp, 2) + 1
/gustav
Gustav, I will need to disagree...
https://msdn.microsoft.com/en-us/library/ms675120(v=vs.85).aspx
Rows
Optional. A GetRowsOptionEnum value that indicates the number of records to retrieve. The default is adGetRowsRest.
which means that if you are on the last record, it will only get that one
using MoveFirst, it will get "the rest", no need to specify the number of records you want.
to test .BOF and .EOF is not needed, because if you "moved" the cursor to the last record, you know you have some records indeed.
https://msdn.microsoft.com/en-us/library/ms675120(v=vs.85).aspx
Rows
Optional. A GetRowsOptionEnum value that indicates the number of records to retrieve. The default is adGetRowsRest.
which means that if you are on the last record, it will only get that one
using MoveFirst, it will get "the rest", no need to specify the number of records you want.
to test .BOF and .EOF is not needed, because if you "moved" the cursor to the last record, you know you have some records indeed.
Unable to reproduce the issue:
All the following give the same result:
All the following give the same result:
Dim trs1 As Recordset
Dim ta As Variant
Set trs1 = CurrentDb.OpenRecordset("a")
trs1.MoveLast
ta = trs1.GetRows()
Debug.Print UBound(ta)
Set trs1 = Nothing
Set trs1 = CurrentDb.OpenRecordset("a")
ta = trs1.GetRows()
Debug.Print UBound(ta)
Set trs1 = Nothing
Set trs1 = CurrentDb.OpenRecordset("a")
ta = trs1.GetRows(trs1.RecordCount)
Debug.Print UBound(ta)
ASKER
thnx
First you mustcheck if the recordset has data:
Open in new window
Later you must fill the recordset
Open in new window
and then you can get anytjing from the recordset.Best regards.
Antonio (Barcelona, Spain)