No Current Record???

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ineedahelp
    New Member
    • Sep 2006
    • 98

    No Current Record???

    I don't understand why I am getting the error message "No current record" at my code....Do While rs1!Symbol = rs2!Symbol....i t seems that rs1 has values, but rs2 is empty. Any help? Many thanks!!

    Code:
    Private Sub cmbFindLastEssentialData_Click()
     '  On Error GoTo Exit_MyProc
     
       DoCmd.RunSQL "DELETE * FROM LastGoodData;"
     
        strSQL = "SELECT DailyPrice.Symbol, DailyPrice.LocateDate, DailyPrice.MarketPrice " & _
            "FROM DailyPrice, TempSymbol " & _
            "WHERE (((DailyPrice.Symbol) = [TempSymbol]![Symbol])) " & _
            "ORDER BY DailyPrice.Symbol, DailyPrice.LocateDate DESC;"
             
        strSQLTEMP = "SELECT TempSymbol.Symbol" & _
                                " FROM TempSymbol" & _
                                " WHERE (((TempSymbol.Symbol) Is Not Null))" & _
                                " ORDER BY TempSymbol.Symbol;"
    Debug.Print strSQLTEMP
        Set db = CurrentDb
        Set rs1 = db.OpenRecordset(strSQL)
        Set rs2 = db.OpenRecordset(strSQLTEMP)
      
        rs2.MoveFirst
        
        rs1.MoveFirst
        Debug.Print rs1!Symbol & " " & rs2!Symbol
        Do Until rs1.EOF
            Do While rs1!Symbol = rs2!Symbol
                If rs1!MarketPrice <> -(mLSGC) Or -5.25 Then
                    Debug.Print rs1!LocateDate, rs1!Symbol, rs1!MarketPrice
                    strINSERT = "INSERT INTO LastGoodData (LocateDate, Symbol, MarketPrice) VALUES (#" & rs1!LocateDate & "#, '" & rs1!Symbol & "', " & rs1!MarketPrice & ");"
                    Debug.Print strINSERT
                    db.Execute strINSERT, dbFailOnError
                    Exit Do
                Else    'only for -5.25 data
                Debug.Print "I'm here"
                    rs1.MoveNext
                    If rs1!Symbol <> rs2!Symbol Then
                        strINSERT = "INSERT INTO LastGoodData (LocateDate, Symbol, MarketPrice) VALUES (#" & rs1!LocateDate & "#, '" & rs1!Symbol & "', " & rs1!MarketPrice & ");"
                        Debug.Print strINSERT
                        db.Execute strINSERT, dbFailOnError
                        Exit Do
                    ElseIf rs1.EOF Then
                        MsgBox "rs1 eof"
                        strINSERT = "INSERT INTO LastGoodData (LocateDate, Symbol, MarketPrice) VALUES (#" & rs1!LocateDate & "#, '" & rs1!Symbol & "', " & rs1!MarketPrice & ");"
                        Debug.Print strINSERT
                        db.Execute strINSERT, dbFailOnError
                        Exit Do
                    End If
                    
                End If
            Loop
            rs2.MoveNext
        Loop
        '    rs2.MoveNext
        '    If Not rs2.EOF Then
        '        Debug.Print rs2!Symbol
        '    End If
        'Loop
        MsgBox "Table updated successfully"
    
        rs1.Close
        rs2.Close
        Set rs1 = Nothing
        Set rs2 = Nothing
        Set db = Nothing
    
    End Sub
    Last edited by NeoPa; Jan 29 '07, 11:29 PM. Reason: Tags for Layout
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32662

    #2
    You do an rs2.MoveNext at the end of your Do Loop but don't ever seem to check for rs2.EOF. I expect this would cause you to hit that error.

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32662

      #3
      In future, please do some trimming work before requesting debugging help.
      You should be looking to test code which has all the lines stripped out which are not relevant to the error. When this has been done then post this stripped down version (that still exhibits the problem in the same way) in your question. This will help you find the problem and also save time for our experts going through irrelevant lines of code.

      MODERATOR.

      As an illustration (It's not enormously shorter, but does save some time going through)
      Code:
      Private Sub cmbFindLastEssentialData_Click()
       
          strSQL = "SELECT DailyPrice.Symbol, DailyPrice.LocateDate, DailyPrice.MarketPrice " & _
              "FROM DailyPrice, TempSymbol " & _
              "WHERE (((DailyPrice.Symbol) = [TempSymbol]![Symbol])) " & _
              "ORDER BY DailyPrice.Symbol, DailyPrice.LocateDate DESC;"
               
          strSQLTEMP = "SELECT TempSymbol.Symbol" & _
                                  " FROM TempSymbol" & _
                                  " WHERE (((TempSymbol.Symbol) Is Not Null))" & _
                                  " ORDER BY TempSymbol.Symbol;"
          Set db = CurrentDb
          Set rs1 = db.OpenRecordset(strSQL)
          Set rs2 = db.OpenRecordset(strSQLTEMP)
        
          rs2.MoveFirst
          
          rs1.MoveFirst
          Do Until rs1.EOF
              Do While rs1!Symbol = rs2!Symbol
                  If rs1!MarketPrice <> -(mLSGC) Or -5.25 Then
                      strINSERT = "INSERT INTO LastGoodData (LocateDate, Symbol, MarketPrice) VALUES (#" & rs1!LocateDate & "#, '" & rs1!Symbol & "', " & rs1!MarketPrice & ");"
                      db.Execute strINSERT, dbFailOnError
                      Exit Do
                  Else    'only for -5.25 data
                      rs1.MoveNext
                      If rs1!Symbol <> rs2!Symbol Then
                          strINSERT = "INSERT INTO LastGoodData (LocateDate, Symbol, MarketPrice) VALUES (#" & rs1!LocateDate & "#, '" & rs1!Symbol & "', " & rs1!MarketPrice & ");"
                          db.Execute strINSERT, dbFailOnError
                          Exit Do
                      ElseIf rs1.EOF Then
                          strINSERT = "INSERT INTO LastGoodData (LocateDate, Symbol, MarketPrice) VALUES (#" & rs1!LocateDate & "#, '" & rs1!Symbol & "', " & rs1!MarketPrice & ");"
                          db.Execute strINSERT, dbFailOnError
                          Exit Do
                      End If
                  End If
              Loop
              rs2.MoveNext
          Loop
      End Sub

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32662

        #4
        Another problem with your code - related or unrelated to your current issue I don't know - is :
        Code:
        If rs1!MarketPrice <> -(mLSGC) Or -5.25 Then
        This will always be TRUE as the value -5.25 is non-zero. It is not being compared to anything so returns the value directly.

        Comment

        Working...