Below are my code and i m still getting the error:
Run time error ‘3021’;
Either BOF or EOF is True, or the current record has been deleted; the
operation requested by the application requires a current record

oRsPage.AddNew
                For iColumnIndex = 0 To .Fields.Count - 1
                    oRsPage.Fields(iColumnIndex).Value = .Fields(iColumnIndex).Value
                Next
                oRsPage.Update
                .MoveNext
            Loop
        End If
    End With
    Set oRs = Nothing
    
    'get the number of rows in the query
    Set oRs = New ADODB.Recordset
    With oRs
        .Open SQL_COUNT, goConn, adOpenForwardOnly, adLockReadOnly
        If Not oRs.EOF Then Rows = Field2Long(.Fields(0).Value)
    End With
    
    Set mvarResult = oRsPage
    GetPagedRecordset = True

exitPoint:
    'clean up
    On Error Resume Next
    oRs.Close
    Set oRs = Nothing
    
    Set oRsPage = Nothing
    Exit Function

Please give me a solution

Edited 6 Years Ago by __avd: Added [code] tags. Encase your code in: [code] and [/code] tags.

With oRs
        .Open SQL, goConn, adOpenForwardOnly, adLockReadOnly
        'we will need a recordset, whether or not there is any data
        Set oRsPage = CloneRecordsetStructure(oRs)  'check if there is any data
        
        If .EOF Then
            'exit now - no data - but query was successful
            Rows = 0
            Set mvarResult = oRsPage

            GetPagedRecordset = True
            GoTo exitPoint
        End If

       
        .Move (PageNumber - 1) * PageSize
        If Not .EOF Then
         
            Do While Not .EOF And iRowIndex < PageSize
                iRowIndex = iRowIndex + 1
                
                'copy the recordset to the
                oRsPage.AddNew
                For iColumnIndex = 0 To .Fields.Count - 1
                    oRsPage.Fields(iColumnIndex).Value = .Fields(iColumnIndex).Value
                Next
                oRsPage.Update
                .MoveNext
            Loop
        End If
    End With
    Set oRs = Nothing
    
    'get the number of rows in the query
    Set oRs = New ADODB.Recordset
    With oRs
        .Open SQL_COUNT, goConn, adOpenForwardOnly, adLockReadOnly
        If Not oRs.EOF Then Rows = Field2Long(.Fields(0).Value)
    End With
    
    Set mvarResult = oRsPage
    GetPagedRecordset = True

exitPoint:
    'clean up
    On Error Resume Next
    oRs.Close
    Set oRs = Nothing
    
    Set oRsPage = Nothing
    Exit Function
errHandle:
    mstrLastError = "Object: " & App.Title & TypeName(Me) & "<br>" & _
                "Module: GetPagedRecordset" & "<br>" & GetAdoError(goConn, Err.Description)
    Resume exitPoint
    Resume

The actual code and please provide me the solution asap

Edited 6 Years Ago by Jagana2005: missed some code and now provided the actual one

When this error occurs?
Only when you reach the "last page", or every time?
(Seems to me you are "paging" your recordset)

If occur only when you reach the "last page", is because ADO can't move

.Move (PageNumber - 1) * PageSize

this number of records.
Example: your page supports 10 records, your recordset return 25 lines. First "page" ok, second "page" ok, but the third one generates error cause they don't move all records requested.


Please, detect the exact line of error (when error occurs, press "Debug" or, if you have a error trap - seems to have -, when your custom message appears press <CTRL> + <SCROLL LOCK> and type RESUME after your message, then press F8 - or simply temporarily disable your error trapping) if it not help you.


Particularly, I suggest you to try using GetString method, you probably code less and avoid certain errors.


Good luck,

Sidnei

This article has been dead for over six months. Start a new discussion instead.