473,320 Members | 2,162 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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 28013
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Salad | last post by:
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...
1
by: RC | last post by:
If I want to explicitly save the record before executing a Close action. Which of the following should I use? Or does it depend on whether it is based on a Form or something else? If Me.Dirty...
0
by: Mike MacSween | last post by:
The user did this, she said. Changed a value in a drop down list (which will have changed an integer value in a field in the main table which is a FK), and edited some text in a text box. Then...
6
by: Squirrel | last post by:
I have a command button on a subform to delete a record. The only statement in the subroutine is: DoCmd.RunCommand acCmdDeleteRecord The subform's recordsource is "select * from tblVisit order...
4
by: WJA | last post by:
I'm probably missing something here but I can't understand the following. When 2 users try to save a record with the same primary key (a number field), the first record saves as expected, but the...
2
by: deko | last post by:
I'm trying to expand a popup form and make additional controls available by making the form footer visible and resizing the form. This works: Me.FormFooter.Visible = Me!tglAdvanced.Value...
0
by: MLH | last post by:
Running the following procedure, Access 97 is giving me a 2465 error in line #250. Anyone know why? MySQL is a global var in the app. This is running in frmVehicleChooserForm. Private Sub...
2
by: Coolboy55 | last post by:
Hi, I'm using the Form_Dirty event to run DoCmd.RunCommand acCmdSaveRecord, but it does not appear to be working, although the event does trigger. I want the record on the main form to be saved...
2
by: Wayne | last post by:
I've noticed a behaviour in A2007 that doesn't appear in A2003. The problem is appearing in a native A2007 database and an A2003 database running in A2007. If I press a command button to delete a...
5
by: Lebbsy | last post by:
After displaying search results, I want to be able to double click the identity number field and then the input form SubmissionDetails becomes the display form for the results of the data matching...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.