473,407 Members | 2,314 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,407 software developers and data experts.

How Do I Cancel Changes on Both Main and Sub Forms Using a Single Button on Main

12
Hello,

I have a Main Form, which also contains a SUB FORM. My SUB FORM contains Text Boxes and Check Boxes. CANCEL button on the MAIN FORM only undo's the data on the MAIN FORM. Kindly tell me a way to UNDO the changes in SUB FORM as well using the same CANCLE button on the MAIN FORM.

I tried to find an answer in the questions asked in the past, but i found it difficult to understand, as i am a rookie. Please help.

I have seen that 1st CODE Undo's all the changes in MAIN FORM.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Cancel_Click()
  2. On Error GoTo Err_Cancel_Click
  3.  
  4. Me.Undo
  5. DoCmd.Close
  6.  
  7. Exit_Cancel_Click:
  8.     Exit Sub
  9.  
  10. Err_Cancel_Click:
  11.     MsgBox Err.Description
  12.     Resume Exit_Cancel_Click
  13.  
  14. End Sub
And the 2nd Code is helpful to Undo the changes on subform. In the 2nd Code, "Spec" refers to the name of my SUBFORM and "Cancel" is the name of my command button on the MAIN FORM.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Cancel_Click()
  2.  
  3.    On Error Resume Next
  4. Application.Echo (False)
  5. Me!Spec.SetFocus
  6. DoCmd.RunCommand (acCmdUndo)
  7. Me!Cancel.SetFocus
  8. Application.Echo (True)
  9.  
  10.     DoCmd.Close
  11.  
  12. End Sub
Can any one please help me in getting these two codes together so that changes in MAIN FORM and SUBFORM can be done simultaneously?

Thanks in advance!!

Regards,
Anjani
Jan 17 '13 #1
5 3146
NeoPa
32,556 Expert Mod 16PB
See Referring to Items on a Sub-Form for some understanding, but your question is well presented (I had to merge the two halves together but a lot of good information was included anyway).

Try this :
Expand|Select|Wrap|Line Numbers
  1. Private Sub Cancel_Click()
  2.     With Me
  3.         Call .Undo
  4.         Call .Spec.Form.Undo
  5.     End With
  6.     Call DoCmd.Close
  7. End Sub
Jan 17 '13 #2
Anjani
12
Thank u sir for ur reply. When i made changes as per your code, following things happened: -

1.Changes made on MAIN FORM only and CANCEL button pressed, then changes are undone. (As per requirement)
2.Changes made on MAIN FORM and then changes made on SUB FORM. After pressing CANCEL button, none of the changes are undone. (Both the changes should be undone)
3.Changes made on SUB FORM only and pressed CANCEL, then the changes are still present on reopening of the form.(It should be undone)

Point 1 is as per requirement, but points 2 & 3 are still bugging me. Please help.Thanks
Jan 18 '13 #3
NeoPa
32,556 Expert Mod 16PB
I fail to see what could possibly be going wrong with this code if your description of the situation is accurate. Maybe you could attach a copy of your database for me to check it here. See Attach Database (or other work).
Jan 19 '13 #4
TheSmileyCoder
2,322 Expert Mod 2GB
First off, what you are describing is accurate, and it is working as it should. (not how you want of course, but that is a different matter)

The issue is that once you leave a form (this includes going into a subform from a main form, or into a main form from a subform) the record is SAVED.
Undo is meant to undo the changes you are in the process of making, i.e. while the form is dirty, you can reset it back to before you began the edit (but that does not include resetting the autonumber count, so even here you could argue its only a partial undo). Beyond that Access offers a single undo to the last record SAVED, PROVIDED you have NOT left the form.

So in 1) it works because you didn't leave the form.
2) The changes to main form are not undone because you left the form to go to the subform. Changes to subform are not undone because you left the subform to press the Cancel/undo button on the main form.
3) Changes are not undone because you left the subform to press the cancel button.



Now, you cannot simply undo changes to more then 1 record at a time. I have tried various approaches to this, without finding any simple method. I tried transactions once, but it seems access runs the forms within its own workspace and thus the transactions I cancelled were unaffected.


If you REALLY need this, my suggestion would be some use of temporary tables, and binding the form to the temporary tables, with update of main tables as the form is closed (or confirmed save, or similar)
While it is a fancy feature to have, I think you need to make sure this is the right place to spend your time at the moment, or if you should focus your energy on another part of your design.
Jan 19 '13 #5
NeoPa
32,556 Expert Mod 16PB
Thank you Smiley :-) That is the rationale that I couldn't find. Of course you're quite correct and I simply overlooked what I should have known.

@Anjani.
You can stop any data from being saved (until you are ready for it - presumably with a button on your form), but if you do so, then the cursor stays where it was and doesn't leave the form. You absolutely can't work on main and sub record areas at the same time (IE. leaving outstanding work).
Jan 20 '13 #6

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

Similar topics

3
by: CroDude | last post by:
Hi all! I've made a button from scratch derived from a Control class. The main reason why Control and not Button class is used for inheritance is that when deriving from a control class it's...
14
by: clintonG | last post by:
This is an appeal for peer support sent to Microsoft as will be noted in closing. The Login control does not include a Cancel button. The only option is to convert the Login control to a...
1
by: holysmokes99 | last post by:
I am trying to implement a cancel button on my application that ingests a bunch of data from a text file into a database. I have not worked too much with threads, so I am having some trouble. I had...
6
by: Raji16 | last post by:
Hi, I am a new member. i am designing a simple judicial database system. however after creating tables i am a bit confused on setting the relationships between tables :confused: here is the link...
21
by: Darin | last post by:
I have a form w/ a textbox and Cancel button on it. I have a routine to handle textbox.validating, and I have the form setup so the Cancel button is the Cancel button. WHen the user clicks on...
9
by: | last post by:
Hi How to get a reference to main form in a Windows Form 2.0 Application? I'm making a a library and I need a reference to the main form of the application that is using that library. TIA
4
by: martin | last post by:
Hello, Is there a way to make a kind of "cancel" button on a form? Suppose you accidently changed or overwrote some data in a form, then I'd like to leave this form at once and cancel any...
4
by: MaxMax | last post by:
I have a dialog box with a Cancel button that I want to be activable with the ESC key. In the form the Cancel button is connected to the CancelButton property. Now my problem is that the OnClick...
2
by: antmail | last post by:
Hi Guys, Been using this forum to get my answer for quite a while now, but finaly I am stumped. I have a form with a subform. I control on the main form when the data is saved and when it is...
5
by: ghjk | last post by:
I have "cancel" button in php files. I want to write common javascript function for cancel button. When user click cancel button I want to clear php form data. Is it possible? <input id="Cancel"...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...
0
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,...

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.