delete error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • berry
    New Member
    • May 2007
    • 46

    delete error

    Hi all...

    I want to delete the 5 years ago's databases and there is an error occur in the line "rs.delete" . Below is my code.

    The error is:
    "Row cannot be located for updating. Some values may have been changed since it was last read."

    This error will occur when rs reach the row that it should be deleted. What should I do?? Thanks for help.

    Code:
      rs.MoveFirst
        
        Do While (rs.EOF <> True)
            If (DateDiff("yyyy", rs.Fields("dateVar"), Now()) >= 5) Then
        'MsgBox DateDiff("yyyy", rs.Fields("dateVar"), Now())
                rs.delete
            End If
            'rs.Update
            rs.MoveNext
        Loop
  • Dököll
    Recognized Expert Top Contributor
    • Nov 2006
    • 2379

    #2
    Originally posted by berry
    "Row cannot be located for updating. Some values may have been changed since it was last read."
    Code:
      rs.MoveFirst
        
        Do While (rs.EOF <> True)
            If (DateDiff("yyyy", rs.Fields("dateVar"), Now()) >= 5) Then
        'MsgBox DateDiff("yyyy", rs.Fields("dateVar"), Now())
                rs.delete
            End If
            'rs.Update
            rs.MoveNext
        Loop
    Greetings, berry!

    Are you able to read the data you're hoping to update/delete?
    Last edited by Dököll; Jun 29 '07, 01:31 AM. Reason: Text delete

    Comment

    • berry
      New Member
      • May 2007
      • 46

      #3
      Originally posted by Dököll
      Greetings, berry!

      Are you able to read the data you're hoping to update/delete?
      Hi Dokoll,
      Thank you for your reply.
      Ya, it can read the data. It can calculate the date different within the date in database and today's date. So it means that the row can be read right??
      But when reach to the rs.delete, the error will occur.
      I wonder what's the problem over there..
      Hope can get the answer..
      Thanks...

      Comment

      • Killer42
        Recognized Expert Expert
        • Oct 2006
        • 8429

        #4
        Doesn't it automatically move to the next record after deleting? If so, then you'd need to skip the MoveNext. Otherwise, I don't know what the problem is. Perhaps the underlying data was changed by another process while you were moving through this recordset.

        Comment

        • Killer42
          Recognized Expert Expert
          • Oct 2006
          • 8429

          #5
          Originally posted by berry
          Code:
          rs.MoveFirst
          Do While (rs.EOF <> True)
            If (DateDiff("yyyy", rs.Fields("dateVar"), Now()) >= 5) Then
              'MsgBox DateDiff("yyyy", rs.Fields("dateVar"), Now())
              rs.delete
            End If
            'rs.Update
            rs.MoveNext
          Loop
          I was just thinking, wouldn't it be better to use a simple delete query to do this? Something like:
          DELETE FROM tablename WHERE dateVar >= #your-cutoff-date#

          Comment

          • berry
            New Member
            • May 2007
            • 46

            #6
            Originally posted by Killer42
            I was just thinking, wouldn't it be better to use a simple delete query to do this? Something like:
            DELETE FROM tablename WHERE dateVar >= #your-cutoff-date#
            Hi killer42,
            I can't use this code because i need to compare to the date in the database, I don't know the cut-off-date.

            Comment

            Working...