473,800 Members | 2,711 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can you stop a form from updating the database when exiting?

52 New Member
How can I stop a form from updating the database when a user closes the form? I have a form which is used for referencing, additions, and modifications but every time the form is closed with no modifications the entry which is being displayed is then stored in the database causing duplicates. My hope is to only allow additions and or modifications if they select the proper command button. If they just close the form I would like nothing stored to the database. Because the form is used for reference I have the Data Entry set to NO. Is there an easy way to do this?

Please help…
Birky
May 24 '07 #1
12 3507
NeoPa
32,579 Recognized Expert Moderator MVP
In the OnClose event procedure for your form, include something like :
Expand|Select|Wrap|Line Numbers
  1. Me.Dirty = False
I believe the following works too :
Expand|Select|Wrap|Line Numbers
  1. Call Me.Undo
May 25 '07 #2
Birky
52 New Member
This works if the code is behind a control object which is calling the DoCmd.Close function but if the Forms CloseBox (upper X on the forms border) is used the record is saved before the form is closed. Any idea how I can get this to stop updating and just close the form straight away? Note I have tried the both the Undo and Dirty options within the forms OnClose event and neither seem to stop the saving if this X is selected.

Expand|Select|Wrap|Line Numbers
  1. Private Sub CmdExit_Click()
  2. On Error GoTo Err_CmdExit_Click
  3.  
  4.     Call Me.Undo
  5.     DoCmd.Close
  6.  
  7. Exit_CmdExit_Click:
  8.     Exit Sub
  9.  
  10. Err_CmdExit_Click:
  11.     MsgBox Err.Description
  12.     Resume Exit_CmdExit_Click
  13.  
  14. End Sub
  15.  
May 31 '07 #3
MMcCarthy
14,534 Recognized Expert Moderator MVP
Try putting this in the On Close event.
Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub Form_Close()
  3.     ' Undo the current record
  4.     DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70
  5. End Sub
  6.  
For some reason Dirty doesn't read True in the On Close event.

Mary
Jun 1 '07 #4
NeoPa
32,579 Recognized Expert Moderator MVP
Mary,
Do you know why Me.Undo (or even Call Me.Undo) doesn't work?
Jun 1 '07 #5
MMcCarthy
14,534 Recognized Expert Moderator MVP
Mary,
Do you know why Me.Undo (or even Call Me.Undo) doesn't work?
Something to do with the form losing focus in the close event. Same problem with Me.Dirty.
Jun 1 '07 #6
MMcCarthy
14,534 Recognized Expert Moderator MVP
Something to do with the form losing focus in the close event. Same problem with Me.Dirty.
For the sake of experimentation probably should be tried as

Expand|Select|Wrap|Line Numbers
  1.  Forms!frmName.Undo
Jun 1 '07 #7
NeoPa
32,579 Recognized Expert Moderator MVP
Thanks.
So, when you use the DoCmd form it passes control out of it's own module to do the job. That makes a sort of sense I suppose.
Jun 2 '07 #8
Lysander
344 Recognized Expert Contributor
This works if the code is behind a control object which is calling the DoCmd.Close function but if the Forms CloseBox (upper X on the forms border) is used the record is saved before the form is closed. Any idea how I can get this to stop updating and just close the form straight away? Note I have tried the both the Undo and Dirty options within the forms OnClose event and neither seem to stop the saving if this X is selected.
I would disable the Forms CloseBox using forms properties and add my own Close button. That way, I can make sure the form is closed the way I want it to be closed. Having said that, I had a similar problem problem, with records being saved before I was ready to save them and spent ages putting all sorts of fixes and traps in. Worked fine in London on a PC, but when system went live in Africa running on laptops, certain ways of pressing those rotten touchpads would save the record. Only by disabling the touchpad and using mice on the laptop would the problem go away.
Jun 2 '07 #9
MSeda
159 Recognized Expert New Member
Birky,
aside from the discussion on how to undo the changes made on the form. I'm curious as to how it is that the duplicate record is being created in the first place. How does the user select which record to view/edit or select to add a new record. do you have a combo box or record selectors on the form or have you employeed some other method of navigation?
It seems to me, the fact that a duplicate record is being created indicates that some how the existing record the user is accessing is erroneously being populated into a new record rather than the user viewing the existing record.
Jun 2 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

16
12665
by: deko | last post by:
I have a sub routine that searches the Outlook PST for a message sent to/from a particular email address. Obviously, this can take a long time when the PST contains thousands of messages. I'd like to put a button on my Access 20003 form that will stop the sub routine when clicked. I know I can press Ctl + Break and stop the code, but is there a more graceful way to do this programmatically? Should I use SendKeys? Also, it would be...
25
10275
by: Lyn | last post by:
Hi, I am working on a genealogy form. The only table (so far) lists everybody in the family, one record per person. Each record has an autonum ID. The parent form (frmMainForm) displays the data in each record, which includes the ID of the father and the mother (who also have records in the table). One record per form. I have a Tab Control in the form, and in one of the tabs I have a subform (sfmSiblings) in which I wish to list...
4
6926
by: deko | last post by:
I'm a little nervous about slamming my database with a dozen Update queries in a loop that all modify RecordSources of open forms. Will the use of DoEvents and/or a Sleep function ameliorate any risk involved in doing this? Should I include a Requery in the loop after executing each query? For example: For each varQry in Array("qryDeleteOldTransactions", _ "qryDeleteClient Acct", etc., etc.) db.Execute varQry
8
3524
by: Matt Theule | last post by:
While stepping through an ASP.NET project, I found that data was being inserted into my database even though I was not stepping through the code that inserted the data. I have a single page with inline code. The page has a Datagrid, a textbox and a button. When the button is clicked, the value of the textbox is inserted into the table whose contents are displayed on the page. The problem occurs when I set a breakpoint on a line *IN*...
2
1188
by: Tom | last post by:
I'm making a database input form that has many text boxes bound to DB fields. I've written a validatedTextBox class that inherits from textBox but validates the input data. It does this with code that overrides the "onValidating" event of textbox. It all works great except if I exit the form (by clicking the x in the upper right corner) with invalid data in a textbox, my onValidating routine gets called and I am prevented from...
6
5255
by: John (Z R) L | last post by:
Hi all, I am very new to programming, and I chose to study the Python language before C++. I am currently using the Wikibooks "Non-Programmer's Tutorial for Python", and am up to the section "Who goes there"? http://en.wikibooks.org/wiki/Non-Programmer%27s_Tutorial_for_Python/Who_Goes_There%3F But after clicking "run module" for " a = 1
6
15035
by: Alan Isaac | last post by:
I'm fairly new to Python and I've lately been running a script at the interpreter while working on it. Sometimes I only want to run the first quarter or half etc. What is the "good" way to do this? Possible ugly hacks include: - stick an undefined name at the desired stop point - comment out the last half I do not like these and assume that I have overlooked the obvious.
9
3342
by: mtgrizzly52 | last post by:
Hi all, I've looked for an answer for this in lots of books, online in several discussion groups and have not found the answer which I feel may be very simple. What I want to do is have a switchboard with several active buttons on it for entering new data, updating data, reports etc. The new data and report stuff is easy, but the update button has me baffled. What I want to have happen is when the update button is clicked, a parameter...
11
11536
by: zgh1970 | last post by:
Hi, Friends, I need to know how to stop all database process even after db2stop. How can I stop all database processes? I have finished upgraded our system test and UAT region from 32-bit to 64-bit. I followed the following for my system test region: 1. log on aix with root 2. stop the instance 3. db2iupdt -w 64 instance
0
9691
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
10507
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...
0
10036
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9092
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7582
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
5473
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...
0
5607
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3765
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2948
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.