Sudha
11-10-2001, 11:21 PM
hi,
how can i cancel an update on both the main form and subform? I have a cancel button on my main form. using this how can i cancel the updates on both the forms? if i give cancel = true, with msgbox, in the before update of the main form only the mainform's changes gets cancelled.if i give it both on the main and subform, it msgbox asks twice if the changes should be cancelled
sudha
sudha
The_Doc_Man
11-13-2001, 07:24 AM
This is a guess.
Try doing an explicit DoCmd.UNDO of the sub-form in the routine doing the CANCEL of the main form.
However, it is possible that if your referential integrity is set incorrectly, you might not get this to work so easily.
John M
11-30-2001, 12:01 AM
Sudha,
Did you find out eventually how to do it as I also have the same dilemma. How can cancel update work both on main form and subform??
Thanks.
marrett
11-30-2001, 02:55 AM
I had the same problem. Thsi is how io solved it.
First add a cancel button to the main srceen then add and unbound field call Dontsave to your form. (You can make this field invisible. In the Cancel event Then create an event that set the field equal to 1 This is trhe code behind my button:
On Error GoTo Err_Command17_Click
Me!Dontsave = 1
DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70
DoCmd.Close
Exit_Command17_Click:
Exit Sub
Err_Command17_Click:
Resume Exit_Command17_Click
Then in the before update of the subform:
If Forms!form1!Dontsave = 1 Then
DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70
End If
Forms!form1!Dontsave = 0
This closes the form to update the screen. You can reopen it in the same place by adding the open statement to the before update event. Before you close the form ave your id or what ever you need to open in the same place.
I hope this helps.
Maria
Pat Hartman
11-30-2001, 04:33 AM
Once you have moved focus to the subform, the data from the main form has been saved. Therefore, there is NO way to cancel the update of the main form, you must delete the record if it was an insert. If you want to be able to back out changes to the main form AFTER they have already been saved to the table, you would need to keep a copy of the original values in hidden, unbound fields and then in your cancel procedure, get the record and update it to the previous values and save it.
See my response - http://www.access-programmers.co.uk/ubb/Forum4/HTML/005005.html
[This message has been edited by Pat Hartman (edited 11-30-2001).]