invalid row number

when executing the following code, I get an error from the datagrid:

            esql2 = "select * from tblOrgMonthlyFunds where Inkind = 0"
            rec2.Open (esql2), conn, adOpenDynamic, adLockOptimistic
            rec2.AddNew
                      
            rec2!MonthlyID = MonthlyID
            rec2!AgencyID = AgencyID
            rec2!Program = Combo1
            rec2!Description = Text2
            rec2!Inkind = 0
            rec2!GrossAmount = Text3
            rec2!NetAmount = Text4
            rec2!InKindAmount = 0
            
            Set OrgMR2.DataGrid2.DataSource = rec2
            
            DataGrid2.Columns(0).Width = 0
            DataGrid2.Columns(1).Width = 0
            DataGrid2.Columns(2).Width = 0
            DataGrid2.Columns(8).Width = 0


            rec2.Update
            
         
Text2 = ""
Text3 = ""
Text4 = ""
          

SumTotal = 0
For i = 0 To DataGrid2.ApproxCount - 1
SumTotal = SumTotal + DataGrid2.Columns(7).CellValue(DataGrid2.GetBookmark(i))
Next
NetTotal = SumTotal

SumTotal = 0
For i = 0 To DataGrid2.ApproxCount - 1
SumTotal = SumTotal + DataGrid2.Columns(6).CellValue(DataGrid2.GetBookmark(i))
Next
GrossTotal = SumTotal

Open in new window


The error is "invalid row number" and it occurs on line 32

Any ideas why this is happening?
al4629740Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

p_sieCommented:
Did you check the value of DataGrid2.GetBookmark(i)) when executing?
I bet that's where teh solution will be
0
al4629740Author Commented:
i = 1. During the error.  I don't see where the error is
0
eemitCommented:
- GetBookmark Method Returns a value containing a bookmark for a row relative to the current row in a DataGrid control.
DataGrid2.GetBookmark(1) - Returns bookmark of the row following current row.
- Furthermore getting the ApproxCount property will query the underlying data source.

Therefore it is better to iterate through underlying recordset.

Dim oRs As ADODB.Recordset
Set oRs = Me.DataGrid2.DataSource
...
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.