469,573 Members | 1,661 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,573 developers. It's quick & easy.

Docmd.Runcommand accmdsaverecord vs Me.Dirty = False

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.

Nov 12 '05 #1
2 26208
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.

Nov 12 '05 #2
Allen Browne wrote:
Access applies the RunCommand to whichever form happens to have focus. That
may be the form that contains the code.
Thanks Allen. Who knows what's going on. The form this occurred on is
called by another form. The code is sitting in the same form when the
runcommand was called. But who knows, maybe something, somewhere, some
action makes Access think it's in the calling form. So I will take your
advice and use the safer method.

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.


Some of the error messages that are displayed would be considered obtuse
by the most erudite.
Nov 12 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Lebbsy | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.