invalid row number

Posted on 2014-08-04
Last Modified: 2014-08-11
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!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

Text2 = ""
Text3 = ""
Text4 = ""

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

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

Open in new window

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

Any ideas why this is happening?
Question by:al4629740
    LVL 9

    Expert Comment

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

    Author Comment

    i = 1. During the error.  I don't see where the error is
    LVL 15

    Accepted Solution

    - 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

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
    If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

    755 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

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now