Results 1 to 6 of 6
  1. #1
    2 Star Lounger
    Join Date
    May 2002
    Location
    Jerusalem, Israel
    Posts
    187
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I have this code, which is giving me an 'Update or CancelUpdate without AddNew or Edit' error 3020.

    Private Sub Form_BeforeUpdate(Cancel As Integer)

    If MsgBox("Do you want to save changes?", vbYesNo + vbQuestion) = vbNo Then
    Me.Undo
    Else
    Me.DateModified = Date
    Me.WhoModified = CurrentUser()
    End If
    End Sub

    I did a bit of research on the Internet and found that you have to use a .Edit command somewhere in the code, followed by a .Update command, but I can't figure out how to do it.

    Can anyone help?

    Thanks,

    JoeK

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    Instead of the line

    Me.Undo

    use

    Cancel = True

  3. #3
    2 Star Lounger
    Join Date
    May 2002
    Location
    Jerusalem, Israel
    Posts
    187
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks, Hans, but I still get the error. The debugger always brings me to this part of the code:

    Me.WhoModified = CurrentUser()

    The funny thing is that every time I think I have fixed it (ie: I don't get the error) and then log in as a different user, I get the error again.

    Is there anything else I can try?

    Thanks,

    JoeK

    ============
    UPDATE: I couldn't find a way out of this error. However, I did isolate the following code as the cause of the problem:

    Me.DateModified = Date
    Me.WhoModified = CurrentUser()

    I removed that code from the Before Update event and put it into an On Dirty event. I figured that it doesn't matter if the data in the fields change before the record is saved. If the user decides not to save the record, then the data in these two fields will revert to their original state. If the user saves the changes, the changed data in the fields will also be saved.

    Now I no longer get the error, which I'm happy about. Although I am curious as to why I got the error to begin with - I have the exact same code (as what I inserted in my original post) running perfectly well in another database.

  4. #4
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,623
    Thanks
    3
    Thanked 60 Times in 60 Posts
    [quote name='joek' post='791629' date='31-Aug-2009 22:37']Now I no longer get the error, which I'm happy about. Although I am curious as to why I got the error to begin with - I have the exact same code (as what I inserted in my original post) running perfectly well in another database.[/quote]
    Is the other database running under Access 2007, or is it on an older version? I've seen a few situations where things that worked fine in 2002 or 2003, do not in 2007.
    Wendell

  5. #5
    2 Star Lounger
    Join Date
    May 2002
    Location
    Jerusalem, Israel
    Posts
    187
    Thanks
    0
    Thanked 0 Times in 0 Posts
    [quote name='WendellB' post='791646' date='01-Sep-2009 14:29']Is the other database running under Access 2007, or is it on an older version? I've seen a few situations where things that worked fine in 2002 or 2003, but not in 2007.[/quote]

    Both DBs are 2007

  6. #6
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,623
    Thanks
    3
    Thanked 60 Times in 60 Posts
    [quote name='joek' post='791769' date='01-Sep-2009 22:54']Both DBs are 2007[/quote]
    OK - are both databases using the .MDB format or is one or the other or both in the .ACCDB format? Also, is User Security activated on both, or is it set the the default security file?
    Wendell

Posting Permissions

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