Solved

"Rowset does not support fetching backward"

Posted on 2007-11-27
4
1,241 Views
Last Modified: 2013-12-25
Hi,

The following snippet of code results in error "Rowset does not support fetching backward", in particular the .MoveLast line.

Does anybody see why?

The 2 key elements I am after here are 1) setting the CursorType to adOpenStatic in order to have the RecordCount be set, and 2) use CopyFromRecordSet (b/c I find it very convenient)

Thank you in advance for your advice.

Dim rs As ADODB.Recordset
    Set rs = New ADODB.Recordset
    rs.CursorType = adOpenStatic
   
    With rs
        .ActiveConnection = cn
        Dim sql As String
        .Open "exec sproc " 'sql
        Sheet4.Range("A" & CStr(FIRST_ROW)).CopyFromRecordset rs
        .MoveLast
        recCnt = rs.RecordCount
        ' MsgBox "Rec Cnt " + CStr(rs.RecordCount)
        .Close
    End With
   
    cn.Close
    Set rs = Nothing
    Set cn = Nothing

Dim rs As ADODB.Recordset

    Set rs = New ADODB.Recordset

    rs.CursorType = adOpenStatic

    

    With rs

        .ActiveConnection = cn

        Dim sql As String

        .Open "exec sproc " 'sql

        Sheet4.Range("A" & CStr(FIRST_ROW)).CopyFromRecordset rs

        .MoveLast

        recCnt = rs.RecordCount

        ' MsgBox "Rec Cnt " + CStr(rs.RecordCount)

        .Close

    End With

    

    cn.Close

    Set rs = Nothing

    Set cn = Nothing

Open in new window

0
Comment
Question by:DotTheBug
4 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
>        Sheet4.Range("A" & CStr(FIRST_ROW)).CopyFromRecordset rs
will consume your recordset.
you probably don't need the .movelast at all...

0
 

Author Comment

by:DotTheBug
Comment Utility
CursorLocation = clientSide did the trick.
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
Comment Utility
PAQed with points refunded (500)

Computer101
EE Admin
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

743 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

16 Experts available now in Live!

Get 1:1 Help Now