Recordset update problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • fieldling
    New Member
    • May 2007
    • 30

    Recordset update problem

    I've written the following code to update a recordset but when I run it I get a Run-time error 3020: Update or CancelUpdate without AddNew or Edit. When I debug it highlights the rs.update line. I've serached this forum and others for an answer but no luck. Anyone got any ideas? Thanks

    [CODE=vb]Option Compare Database

    Public Function fImportdata()
    Dim db As DAO.Database
    Dim rs As DAO.Recordset
    Set db = CurrentDb()
    Set rs = db.OpenRecordse t("Import Query", dbOpenDynaset)
    With rs
    .MoveFirst
    .Edit
    While .EOF = False
    If rs![M1] = "Y" And rs![M2] <> "Y" Then
    rs![M2] = "Y" ' Will update M2 with a Y if M1=Y and M2 is null.
    GoTo MyLabel
    Else
    End If
    If rs![M2] = "Y" And rs![M3] <> "Y" Then
    rs![M3] = "Y" 'Will update M3 with a Y if M1=Y and M2 is null.
    GoTo MyLabel
    Else
    End If
    If rs![M3] = "Y" And rs![M4] <> "Y" Then
    rs![M4] = "Y"
    GoTo MyLabel
    Else
    End If
    If rs![M4] = "Y" And rs![M5] <> "Y" Then
    rs![M5] = "Y"
    GoTo MyLabel

    End If
    MyLabel:
    rs.Update
    rs.MoveNext
    Wend
    End With
    rs.Close
    End Function[/CODE]
    Last edited by debasisdas; Jan 24 '08, 09:39 AM. Reason: ADDED CODE=VB TAGS
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    before assigning the value to recordset use rs.edit

    Comment

    • fieldling
      New Member
      • May 2007
      • 30

      #3
      Originally posted by debasisdas
      before assigning the value to recordset use rs.edit
      I have put .edit in line 10. Is this incorrect?

      Comment

      • daniel aristidou
        Contributor
        • Aug 2007
        • 494

        #4
        Im noy sure which version vb ure usin form the code
        But try adding an end edit command just before update..

        Comment

        • fieldling
          New Member
          • May 2007
          • 30

          #5
          Originally posted by daniel aristidou
          Im noy sure which version vb ure usin form the code
          But try adding an end edit command just before update..
          Thanks for your help.
          It's version 6.3
          It doesn't recognise the EndEdit command although I may not have done it correctly. How would you put that command in?

          Comment

          • fieldling
            New Member
            • May 2007
            • 30

            #6
            Originally posted by daniel aristidou
            Im noy sure which version vb ure usin form the code
            But try adding an end edit command just before update..
            Hi I've managed to fix it and all running smoothly. Thanks for your help.

            Comment

            Working...