Access applies the RunCommand to whichever form happens to have focus. That
may be the form that contains the code.
Me.Dirty is safer, because you are specifying precisely which form you wish
to have the record saved in. It is definately the best approach. The only
downside is that newbies sometimes misunderstand the error message if the
save fails. For example, if it says "The property could not be set" it is
telling you that the save failed; a newbie might think it meant you are not
permitted to set the Dirty property.
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users -
http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
"Salad" <oi*@vinegar.com> wrote in message
news:PG*****************@newsread1.news.pas.earthl ink.net...
A97.
I have a command button to save and exit. I had the code
If Me.Dirty Then
Docmd.RunCommand acCmdSaveRecord
...more code
endif
I was getting an error because a value was not getting set in the
BeforeUpdate event. So I changed it to
If Me.Dirty Then
Me.Dirty = False
...more code
endif
Is there a reason that even tho the record was dirty, the
Docmd.Runcommand would not execute...or at least execute my form's
BeforeUpdate event but the Me.Dirty = False would?
I put a message box in the Forms BeforeUpdate event
msgbox "In BeforeUpdate"
and that always displayed when I used Me.Dirty = False but would not be
displayed if I used Docmd.Runcommand accmdsaverecord.