Results 1 to 7 of 7

Thread: SQL Parameter Query - Rowset Position Cannot be Restarted

  1. #1

    Thread Starter
    Fanatic Member The_Grudge's Avatar
    Join Date
    Jan 2005
    Location
    Canada
    Posts
    836

    SQL Parameter Query - Rowset Position Cannot be Restarted

    I have the following code:

    It works in that my query executes and if I remove the .MoveFirst statement (bold below), but I need that statement in there as my records are sorted in order and I refer to it throughout the program.

    This is the first time I open the recordset and when it gets to that .movefirst statement below I get

    "An Error Has Occurred - Rowset position cannot be restarted"

    Any idears? I notice using a debug.print that it's not setting the cursor type/location to what I specify

    Code:
    strSQL = "My QUERY GOES HERE"
                     
     Dim objCommand As ADODB.Command
     Set objCommand = New ADODB.Command
     
     With objCommand
       .ActiveConnection = SQLCon
       .CommandType = adCmdText
       .CommandText = strSQL
       .Prepared = True
       .Parameters.Append .CreateParameter("ClinicDate", adDate, adParamInput, , dtDate)
       .Parameters.Append .CreateParameter("Institution", adChar, adParamInput, 4, strInstitution)
          
    
      rsGetTodaysData.CursorType = adOpenDynamic
      Set rsGetTodaysData = objCommand.Execute
      Set objCommand = Nothing
    
    End With
     
    With rsGetTodaysData
       If .BOF <> True And .EOF <> True Then
          .MoveFirst
             Do Until .EOF = True
                If FormInUse.Name = "frmMain" Then
    Last edited by The_Grudge; May 25th, 2018 at 01:32 PM.

  2. #2

    Thread Starter
    Fanatic Member The_Grudge's Avatar
    Join Date
    Jan 2005
    Location
    Canada
    Posts
    836

    Re: SQL Parameter Query - Rowset Position Cannot be Restarted

    Think I got it.

    Changed the line "Set rsGetTodaysData = objCommand.Execute" to say "rsGetTodaysData.Open objCommand". That runs my query and by checking the cursor location and type with a debug.print statement, it also sets those appropriately.

  3. #3
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    5,268

    Re: SQL Parameter Query - Rowset Position Cannot be Restarted

    Don't you need rsGetTodaysData.CursorLocation=adUseClient?
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  4. #4

    Thread Starter
    Fanatic Member The_Grudge's Avatar
    Join Date
    Jan 2005
    Location
    Canada
    Posts
    836

    Re: SQL Parameter Query - Rowset Position Cannot be Restarted

    I put that in too.

  5. #5
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    5,268

    Re: SQL Parameter Query - Rowset Position Cannot be Restarted

    Everything i found to that Error-Message points to CursorLocation=adUseClient missing,
    since adUseServer is the default if omitted
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  6. #6

    Thread Starter
    Fanatic Member The_Grudge's Avatar
    Join Date
    Jan 2005
    Location
    Canada
    Posts
    836

    Re: SQL Parameter Query - Rowset Position Cannot be Restarted

    I had a Set rsGetTodaysData = New Recordset statement at the top of that sub.

    I don't know why, but even though I specified a cursor location and type it wasn't "taking". Not until I changed that statement to rsGetTodaysData.Open objCommand did it work. I had the adUseClient in there earlier and it wasn't working. That's part of it I know but the way I was opening the recordset was causing issues somehow.

  7. #7
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    6,188

    Re: SQL Parameter Query - Rowset Position Cannot be Restarted

    Consider the following lines from the original snippet:

    rsGetTodaysData.CursorType = adOpenDynamic
    Set rsGetTodaysData = objCommand.Execute


    The second one actually creates a brand new recordset. Whatever properties you set before that are gone. It's unnecessary even to allocate a recordset before setting the reference to a brand new one.

    How can you control the CursorLocation of this newly minted recordset?

    Just set Connection.CursorLocation to whatever before Execute-ing the command. Must admit this is an obscure API design by ADO team, probably an after-thought.

    cheers,
    </wqw>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width