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??
 
L

Linq Adams via AccessMonster.com

You wouldn't. When you exit the form Access will automatically save the data.


But you might have a button on your form that performs some function, such as
printing out a report based on the information that you just entered in the
record, or opening a related form and filling in some of the data, such as an
ID number, on that second form. If the record isn't saved, the report won't
print out and the data won't be put into the second form. So you force the
save. Otherwise you'd have to move to another record, move back to the new
record, then press the button. Or you could clode the form, re-open the form,
then find the new record, THEN press the button.

Much easier to just force the "save" by putting the one line of code

If Me.Dirty Then Me.Dirty = False

in the code for the button before performing whatever with the button.
 
L

Linq Adams via AccessMonster.com

Sorry, forgot to add. While you may need to have ***all*** fields populated
in ***your*** database in order to have a valid record worth saving, the same
is not true of all databases. In point of fact, many if not most systems have
data entered over multiple sessions; you simply add validation forcing the
absolutely, positively got to have data to be entered before saving the
record, then other data can be entered later.
 

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

Top