?
Solved

vba getting proper uboundin an array

Posted on 2016-08-08
6
Medium Priority
?
72 Views
Last Modified: 2016-08-11
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 ?
' 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"  

Open in new window



Thanks
fordraiders
0
Comment
Question by:fordraiders
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 total points
ID: 41748256
I found that to happen if the recordset is on the last record.
so, please try to use :
rs1.MoveFirst()
dArrp = rs1.GetRows()

Open in new window

1
 
LVL 2

Expert Comment

by:Antonio Salva Ripoll
ID: 41748258
Hi.

First you mustcheck if the recordset has data:

if not (rs1.bof and rs1.eof) then

Open in new window


Later you must fill the recordset
rs1.movelast
rs1.movefirst

Open in new window

and then you can get anytjing from the recordset.

Best regards.

Antonio (Barcelona, Spain)
1
 
LVL 51

Expert Comment

by:Gustav Brock
ID: 41748394
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

Open in new window

/gustav
1
10 Questions to Ask when Buying Backup Software

Choosing the right backup solution for your organization can be a daunting task. To make the selection process easier, ask solution providers these 10 key questions.

 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 41748400
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.
0
 
LVL 30

Expert Comment

by:hnasr
ID: 41748689
Unable to reproduce the issue:
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)

Open in new window

0
 
LVL 3

Author Closing Comment

by:fordraiders
ID: 41753382
thnx
0

Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question