locked
does it make sense to test if me.dirty = true before statement me.dirty = false? RRS feed

  • Question

  • I'm using "me.dirty = false" to write the information on my form to the database.

    Is it optimal to just run the statement every time I want to be sure the data is saved? Or would be it be better to test to see if me.dirty = true first, then only run the statement "me.dirty = false" if the record is in fact dirty?


    Gordon Prince * (901) 761-3393
    Saturday, January 21, 2012 1:51 PM

Answers

  • I'm using "me.dirty = false" to write the information on my form to the database.

    Is it optimal to just run the statement every time I want to be sure the data is saved? Or would be it be better to test to see if me.dirty = true first, then only run the statement "me.dirty = false" if the record is in fact dirty?


    Although it does no harm to execute "Me.Dirty = False" when the record isn't dirty, benchmark tests show that it is marginally more efficent, in cases where you don't know whether the record is dirty or not, to first test the property and then only set it if the record is actually dirty.  At least, this was true with the original Jet engine used by versions of Access up through Accerss 2003.  With the ACE used by Access 2007 and 10, it may be different, but I have no reason to think so.

    So the construct "If Me.Dirty Then Me.Dirty = False" is slighty -- probably negligibly -- more efficient.  Since it's so little extra code, that's what I do.

     


    Dirk Goldgar, MS Access MVP
    Access tips: www.datagnostics.com/tips.html
    • Marked as answer by Gordon Prince Monday, January 23, 2012 3:50 PM
    Saturday, January 21, 2012 2:10 PM

All replies

  • I'm using "me.dirty = false" to write the information on my form to the database.

    Is it optimal to just run the statement every time I want to be sure the data is saved? Or would be it be better to test to see if me.dirty = true first, then only run the statement "me.dirty = false" if the record is in fact dirty?


    Although it does no harm to execute "Me.Dirty = False" when the record isn't dirty, benchmark tests show that it is marginally more efficent, in cases where you don't know whether the record is dirty or not, to first test the property and then only set it if the record is actually dirty.  At least, this was true with the original Jet engine used by versions of Access up through Accerss 2003.  With the ACE used by Access 2007 and 10, it may be different, but I have no reason to think so.

    So the construct "If Me.Dirty Then Me.Dirty = False" is slighty -- probably negligibly -- more efficient.  Since it's so little extra code, that's what I do.

     


    Dirk Goldgar, MS Access MVP
    Access tips: www.datagnostics.com/tips.html
    • Marked as answer by Gordon Prince Monday, January 23, 2012 3:50 PM
    Saturday, January 21, 2012 2:10 PM
  • I'm using "me.dirty = false" to write the information on my form to the database.

    Is it optimal to just run the statement every time I want to be sure the data is saved? Or would be it be better to test to see if me.dirty = true first, then only run the statement "me.dirty = false" if the record is in fact dirty?


    Gordon Prince * (901) 761-3393


    Hi Gordon,

    Though there will be a difference in performance between reading (If Me.Dirty) and writing (Me.Dirty = False), you will not notice this in practice.

    I did a little test. A million times "Me.Dirty = False" took a rounded 4 seconds, and a million times "If Me.Dirty Then Me.Dirty = False" did cost a rounded 3 seconds.

     

    Imb.

    Saturday, January 21, 2012 2:13 PM
  • Gordon Prince wrote:

    I'm using "me.dirty = false" to write the information on my form to the database.

    Is it optimal to just run the statement every time I want to be sure the data is saved? Or would be it be better to test to see if me.dirty = true first, then only run the statement "me.dirty = false" if the record is in fact dirty?

    I've had situations in the past where if you did the me.dirty = false
    needlessly it failed with an error message.     However I don't recall
    what version of Access.   Quite possibly Access 2000.  
    Anyhow this doesn't happen in more recent versions of Access much to my
    surprise a number of years back when I stated you had to do this.   And
    I was wrong as was pointed out.  <smile>

    Tony


    Tony Toews, Microsoft Access MVP
    Tony's Main MS Access pages - http://www.granite.ab.ca/accsmstr.htm
    Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/
    For a convenient utility to keep your users FEs and other files   updated see http://www.autofeupdater.com/

    Tuesday, January 24, 2012 5:16 AM
  • I've had situations in the past where if you did the me.dirty = false
    needlessly it failed with an error message.     However I don't recall
    what version of Access.   Quite possibly Access 2000.  

    HiTony,

    I had no problems with Me.Dirty = False in Access97.

     

    Imb.

    Tuesday, January 24, 2012 8:10 AM
  • Imb-hb wrote:

    I've had situations in the past where if you did the me.dirty = false
    needlessly it failed with an error message.     However I don't recall
    what version of Access.   Quite possibly Access 2000.  

    HiTony,

    I had no problems with Me.Dirty = False in Access97.

    That's what I recall as well.  I think it was on a newer version or so.

    Tony


    Tony Toews, Microsoft Access MVP
    Tony's Main MS Access pages - http://www.granite.ab.ca/accsmstr.htm
    Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/
    For a convenient utility to keep your users FEs and other files   updated see http://www.autofeupdater.com/

    Thursday, January 26, 2012 7:51 PM