Search code examples
sqlvb6

How to solve the "3670: Cursor is not valid" Error in VB6.0


I am working on an application on VB6. I am trying to execute a query but when I try to do an insert into a temporary table it gives me the error "Cursor is not valid." (I don't know if the insert is truly the problem, but from what I have tried it seems to be this). The code is something like this: (this is not the correct query just an example)

 Dim p_C As Connection
 Dim p_R As Recordset
 Dim Sql As String
 Sql = "select d_start,d_finish,name from Table1"
 Sql= Sql & "where id=10"
 Sql=Sql & "Into #tempTable"
 Sql=Sql & "select * from #tempTable"
 Set p_R1 = p_C.OpenRecordset(Sql, dbOpenSnapshot)
  If Not p_R1.EOF Then
     'Do something
  End If

Now the p_R1.EOF gives 3670: cursor is not valid error. If I delete the "Insert into #tempTable" string there is no error. Does anyone know what is the problem? Thank you in advance!


Solution

  •  Dim p_C As Connection
     Dim p_R As Recordset
     Dim Sql As String
     Sql = "select d_start,d_finish,name "
     Sql= Sql & "Into ##tempTable "
     Sql= Sql & "from Table1 "
     Sql= Sql & " where id=10; "
     p_C.Execute Sql
     Sql=""
     Sql= Sql & "select * from ##tempTable"
     Set p_R1 = p_C.OpenRecordset(Sql, dbOpenSnapshot)
     If Not p_R1.EOF Then
     'Do something
     End If
    

    The problem persisted with the insert statement so I just divided the query. This works very well. Thank you all for the help!