By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,475 Members | 1,910 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,475 IT Pros & Developers. It's quick & easy.

Docmd.Runcommand accmdsaverecord vs Me.Dirty = False

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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.