473,837 Members | 1,621 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Docmd.Runcomman d accmdsaverecord vs Me.Dirty = False

A97.

I have a command button to save and exit. I had the code
If Me.Dirty Then
Docmd.RunComman d 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.Runcomman d 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.Runcomman d accmdsaverecord .

Nov 12 '05 #1
2 28199
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.co m> wrote in message
news:PG******** *********@newsr ead1.news.pas.e arthlink.net...
A97.

I have a command button to save and exit. I had the code
If Me.Dirty Then
Docmd.RunComman d 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.Runcomman d 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.Runcomman d 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
4449
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 set in the BeforeUpdate event. So I changed it to
1
6825
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 Then RunCommand acCmdSaveRecord End If DoCmd.Close or
0
3912
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 clicked on the SaveChanges button, the code behing which is: ****************************************************** Private Sub cmdSave_Click() ' Comments : ' Parameters: - ' Modified :
6
8477
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 by VisitDt" I'm getting this error message: Errno is 2465. Err.description is "Can't find field '|' referred to in your expression"
4
3450
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 second does not produce an error. The "Save" button uses "Docmd.Save" to save the record. If I insert "Me.Dirty = False" before "Docmd.Save" an error is produced. Why doesn't "Docmd.Save" produce an error but instead silently fails to save the...
2
5204
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 DoCmd.DoMenuItem acFormBar, 7, 6, 0, acMenuVer70 But this doesn't:
0
2397
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 CopyMySQLbttn_Click() On Error GoTo ErrorCopyMySQLbttn_Click Dim ThisForm As String ThisForm = Me.Name 100 Dim dtxt As Object
2
3394
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 as soon as it becomes dirty, but even after the Dirty event runs, the record does not show up on the table. Am I missing something? Note: I have a subform as well, in case this has anything to do with it. Thanks! CB55
2
4406
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 record on a single form using DoCmd.RunCommand acCmdDeleteRecord as the code behind the button, when I close that form Access asks me if I want to save the changes to the form. This only happens if the database is an mdb or accdb. If it has...
5
4322
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 value of the selected identity number. With my code below I get a data type mismatch error. Please help me....... Private Sub IdentityNumber_Click() On Error GoTo IdentityNumber_Click_Err On Error Resume Next If (Form.Dirty) Then ...
0
9833
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10867
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10617
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7803
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6989
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5666
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4469
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4036
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3122
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.