Results 1 to 6 of 6
  1. #1
    Rod is offline Expert
    Windows Vista Access 2007
    Join Date
    Jun 2011
    Location
    Metro Manila, Philippines
    Posts
    679

    On Dirty fires but Me.Dirty = False (v2010)

    Code:
     
    Private Sub Form_Dirty(Cancel As Integer)
    If Me.Dirty Then
    MsgBox "dirty"
    Else
    MsgBox "clean"
    End If
    End Sub
    The code above reports "clean!" It seems Me.Dirty is set true much later in the cycle of things since if I include a command button to test the state it returns "dirty."



    Is this a v2010 bug? I don't remember encountering it in earlier versions.

    Has anyone got a workaround?

    I can't find anything relevant on the web.

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    For what purpose are you trying to use the Dirty event?

  3. #3
    Rod is offline Expert
    Windows Vista Access 2007
    Join Date
    Jun 2011
    Location
    Metro Manila, Philippines
    Posts
    679
    Hi RG,

    I have a common sub procedure that synchronises command buttons with the state of the form; one of the buttons is an 'Undo' button that should be disabled if the form is clean and vice versa. The procedure therefore contains an If Me.Dirty condition.

    The procedure is invoked by various events: Current, After Update, etc. including On Dirty. The Me.Dirty condition does not work when the procedure is invoked from the On Dirty event.

    OK, that's what I'm doing. I can program around this by duplicating code in the actual On Dirty event handler or simply by allowing the 'Undo' button to be enabled all the time. However that's not really the point; the Dirty property is not set at the correct point in the processing cycle and this can lead to logic errors.

    I'm fairly sure this is a recent 'bug.' There are examples on the web similar to the code in my first post purporting to demonstrate the use of the On Dirty event - one of the examples I believe is on a Microsoft site! (I've only had v2010 for a few days - I'm having difficulty activating it but that's another story - so I have not yet had an opportunity to check any of my earlier code.)

    I have tried various (nasty) tricks such as toggling the focus to see if I can get the property set - but to no avail. (Forcing Dirty = True in the event handler just causes infinite recursion.)

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    I have not played much with the Dirty event but it is my understanding that it fires when the recordset first goes dirty. I believe it would be safe to "assume" that Dirty is True or about to be True in the Dirty event so the test for Dirty is redundant and unnecessary.

  5. #5
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    I just tested MsgBox "Me.Dirty = " Me.Dirty in the OnDirty event in AccessXP and the value is False. It looks to me as though the Dirty Flag has not been set yet in this event and this has been the case for some time.

  6. #6
    Rod is offline Expert
    Windows Vista Access 2007
    Join Date
    Jun 2011
    Location
    Metro Manila, Philippines
    Posts
    679
    I believe it would be safe to "assume" that Dirty is True or about to be True in the Dirty event so the test for Dirty is redundant and unnecessary.
    "About to be true" is obviously the case!

    No I didn't put a test on the Dirty property in the On Dirty event handler; I'm not quite that stupid. My example was purely to show the 'incorrect' setting of the property.

    My event handler contains a call to another commonly used procedure that contains the test that was failing. I've rewritten the code and duplicated the relevant statements directly in the On Dirty event handler. I dislike duplication since it means any future change has to be done in more than one place.

    Thanks for checking the earlier version. You've saved me a lot of time.

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

Similar Threads

  1. Detect When Two Related Fields are Dirty
    By caddcop in forum Forms
    Replies: 2
    Last Post: 06-09-2011, 05:44 AM
  2. Help filtering a dirty dataset
    By za20001 in forum Queries
    Replies: 0
    Last Post: 04-16-2011, 10:51 AM
  3. Dirty
    By JEPEDEWE in forum Programming
    Replies: 1
    Last Post: 11-13-2010, 04:50 PM
  4. can anybody explain dirty event to me?
    By RedGoneWILD in forum Programming
    Replies: 3
    Last Post: 08-05-2010, 01:50 PM
  5. Delete and Dirty functions
    By Evgeny in forum Programming
    Replies: 3
    Last Post: 05-03-2010, 02:39 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