Help with Me.Dirty

T

TeeSee

If Me.Dirty Then
Me.Dirty = False
Please help me understand the above snippet of code assuming a single
form.

The second I input data into a bound control the form is Dirty.
According to my reference Me.Dirty=True until record is saved.
So now that I have dirtied the form I have changed my mind and want to
bail and so the above code sets the Dirty property to False (which is
fooling Access into thinking that I haven't typed anything at all) Do
I have that correct?
The above code still saves the partial input.

Please explain. Thanks
 
D

Dirk Goldgar

TeeSee said:
If Me.Dirty Then
Me.Dirty = False
Please help me understand the above snippet of code assuming a single
form.

The second I input data into a bound control the form is Dirty.
According to my reference Me.Dirty=True until record is saved.
So now that I have dirtied the form I have changed my mind and want to
bail and so the above code sets the Dirty property to False (which is
fooling Access into thinking that I haven't typed anything at all) Do
I have that correct?

No.

If the form is dirty, setting Me.Dirty = False will force the form to become
"clean" BY SAVING THE RECORD. That's totally arbitrary behavior -- the
designers could just as easily have programmed the property so that setting
it to False performed and undo of all changes to the record -- but it's also
a very handy behavior, because it lets you explicitly force the record to be
saved without using any of the other methods that require the form you're
working with to be the active data object. For that reason alone, every
developer I know has become very fond of using Me.Dirty = False to force a
record save.

If the form is dirty (Me.Dirty = True), you can abort the changes to the
record by calling the form's Undo method:

Me.Undo

That will restore the form's bound fields to their original values.

I don't know of any way to "fool" Access into thinking the record is clean
while retaining any values that have been entered into bound controls. If
there were such a way, I can't think of any situation where using it would
not be a terrible idea.
 
T

TeeSee

No.

If the form is dirty, setting Me.Dirty = False will force the form to become
"clean" BY SAVING THE RECORD.  That's totally arbitrary behavior -- the
designers could just as easily have programmed the property so that setting
it to False performed and undo of all changes to the record -- but it's also
a very handy behavior, because it lets you explicitly force the record tobe
saved without using any of the other methods that require the form you're
working with to be the active data object.  For that reason alone, every
developer I know has become very fond of using Me.Dirty = False to force a
record save.

If the form is dirty (Me.Dirty = True), you can abort the changes to the
record by calling the form's Undo method:

    Me.Undo

That will restore the form's bound fields to their original values.

I don't know of any way to "fool" Access into thinking the record is clean
while retaining any values that have been entered into bound controls.  If
there were such a way, I can't think of any situation where using it would
not be a terrible idea.

Dirk ... I sincerely thank you for that explanation. That has confused
me for some time. Still to this moment it doses't "sound" logical

BUT I now understand it. Thank you again!

Sorry ... But I have to ask .... Why (under what circumstances) would
you want to "Force" a save when possibly half the infomation may be
input when the user decides to exit??
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Me.Dirty Help 2
delete record with blank required field 3
me.dirty with a bound form 3
Validation Code and Me.dirty 2
IF Me.Dirty 2
Form Dirty not firing 10
Me.dirty 2
If, Then Button Code 1

Top