Results 1 to 4 of 4
  1. #1
    MatthewGrace is offline Competent Performer
    Windows 8 Access 2010 64bit
    Join Date
    Jan 2013
    Posts
    159

    Using Me.Dirty in a BeforeUpdate event procedure.


    I'm having difficulty with a common feature of Access programs: a BeforeUpdate confirmation to commit changes, where if the user selects "No (I don't want to commit changes)", the control values go back to their previous value. The issue I have while building the said feature is found in the "me.Dirty = false" line. I normally don't use the "dirty" feature and I cannot figure out why it is tripping Error 2115, Saying that my code in this BeforeUpdate procedure is preventing Access from saving the data to the field.

    My trouble is that if I don't use the .dirty line, then inevitably the user will try again to move the record selector elsewhere, only to be prompted endlessly with this same Messagebox asking if they want to commit changes they've already said no to previously. Thanks for any insight.
    Click image for larger version. 

Name:	code.png 
Views:	10 
Size:	16.4 KB 
ID:	18887

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    Me.Dirty = False causes the data to save or at least try to. You don't want that code in this event.

    Try Me.Undo instead. And should not need the control looping.

    http://www.blueclaw-db.com/access_ev...foreupdate.htm
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Me.Dirty will always be True, in the Form_BeforeUpdate event; how can it not be? If the Form wasn't dirtied, there would be no reason to Save the Record, and the event would never be executed!

    All you need to accomplish your goal is
    Code:
    Private Sub Form_BeforeUpdate(Cancel As Integer)
     If Not Me.NewRecord Then
      If MsgBox("Routing details of this skid have been altered.  Commit?", vbYesNo + vbQuestion, "Skid Manager - Commit Changes") = vbNo Then
       Me.Undo
      End If
     End If
    End Sub

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  4. #4
    MatthewGrace is offline Competent Performer
    Windows 8 Access 2010 64bit
    Join Date
    Jan 2013
    Posts
    159
    Thank you both for your replies. solved.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Dirty event not activating on Access 2007 form
    By newbieX in forum Programming
    Replies: 4
    Last Post: 06-17-2014, 12:57 PM
  2. Replies: 1
    Last Post: 03-29-2014, 07:46 PM
  3. Subform Events Has No BeforeUpdate Event
    By CementCarver in forum Programming
    Replies: 1
    Last Post: 06-25-2013, 01:53 PM
  4. Replies: 3
    Last Post: 05-07-2012, 12:17 PM
  5. can anybody explain dirty event to me?
    By RedGoneWILD in forum Programming
    Replies: 3
    Last Post: 08-05-2010, 01:50 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums