invalid row number

al4629740
al4629740 used Ask the Experts™
on
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?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
Did you check the value of DataGrid2.GetBookmark(i)) when executing?
I bet that's where teh solution will be

Author

Commented:
i = 1. During the error.  I don't see where the error is
Top Expert 2012
Commented:
- 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
...

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial