Results 1 to 5 of 5
  1. #1
    Ashe is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2010
    Location
    Blacksburg VA
    Posts
    65

    Me.Dirty not catching

    I have a bound form with code to undo a record if the user closes the form without saving the changes. For some reason, even after typing and tabbing through controls, Access isn't registering that the form is dirty. (Or I'm not grasping the meaning of "dirty"). The form is opening to a new record should not save the record if the user doesn't say "Save"...

    My code is below:



    Code:
    Private Sub Form_Close()
        If Me.Dirty Then
            DoCmd.SetWarnings False
              DoCmd.RunCommand acCmdUndo
            DoCmd.SetWarnings True
        Else
            MsgBox "didnt catch"
        End If
    End Sub
    Is this because I'm adding a new record and not actually changing an existing record?

  2. #2
    TheShabz is offline Court Jester
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    1,368

  3. #3
    Ashe is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2010
    Location
    Blacksburg VA
    Posts
    65
    According to this link, the record is dirty if a user has made changes. If the user is adding a new record, if this considered "dirty"? The link doesn't address new records.

    Also, this command (If Me.Dirty) does catch on in another sections of my code. That makes me believe that Dirty refers to changes to an existing record and creating new records.

    However, a new record is definitely being made, and the If Me.Dirty command is not triggering as "True". I'm wondering if this has to do with the 60 second refresh of records, but the amount of time since the record was first created also seems to have no impact.

  4. #4
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    It helps if you understand the order of events.

    If you go to this page:
    http://office.microsoft.com/en-us/ac...005186761.aspx

    and then to this part:

    Order of events for forms and subforms

    It will show that the Unload event occurs before the Close event. So the Unload event is when the recordset is unloaded from the form. So, if the form was dirty, it already went through the form's BEFORE UPDATE event and then the recordset has been unloaded and then the form closes. So the form can't be dirty when the form close event occurs.

  5. #5
    Ashe is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2010
    Location
    Blacksburg VA
    Posts
    65
    Thank you Bob! That is a very helpful and interesting link!

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

Similar Threads

  1. On Dirty fires but Me.Dirty = False (v2010)
    By Rod in forum Programming
    Replies: 5
    Last Post: 07-30-2011, 08:42 PM
  2. Dirty
    By JEPEDEWE in forum Programming
    Replies: 1
    Last Post: 11-13-2010, 04:50 PM
  3. Catching record id in a form
    By lupis in forum Programming
    Replies: 6
    Last Post: 05-15-2010, 03:21 PM
  4. Delete and Dirty functions
    By Evgeny in forum Programming
    Replies: 3
    Last Post: 05-03-2010, 02:39 PM
  5. Replies: 1
    Last Post: 04-13-2010, 12:18 PM

Tags for this Thread

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