Full Version: Form with subform Undo or Delete entry not working
UtterAccess Forums > Microsoft® Access > Access Forms
hhh1027
I have form with subform and as I enter data if I go back while still in the record and hit undo or delete is not letting me do it. How can I edit or delete entry if I realize it was wrong entry while still in the form. The source of the data is from table I don't know if that makes diffrence or if i should use query as the source of the data.
Thanks
GrahamMandeno
Hi hhh127
When you move focus from a control on the main form into a subform, the main form record is automatically saved. This is necessary because otherwise, if the main form is on a new record, the subform records wouldn't have any record to link to and relational integrity would break.
And, of course, when you move from one record to another in the subform, the previous record is saved if it has been changed.
You could put code in the BeforeUpdate event of the main form to verify that changes should be saved. This event would fire when moving from the main form to the subform.
If you want to batch all the changes in both the main form and all its related subform records, and commit or undo them all at once, then it is a major undertaking. The simplest way to achieve it is to copy all the required records to temporary tables and base your form and subform(s) on those tables. When the changes are to be saved, you execute a bunch of queried to append/update/delete records from the real tables.
hhh1027
Graham,

Thanks for your response now it makes sence why, but if i want to put the code in the beforevent to ask "do you want to save this record" with Yes or No where yes will save the record and No will undo it how would i do it.

Thanks
Edited by: hhh1027 on Mon Aug 17 20:00:17 EDT 2009.
GrahamMandeno
Something like this:
CODE
Private Sub Form_BeforeUpdate(Cancel as Integer)
If MsgBox("Do you want to save changes to this record?", vbQuestion or vbYesNo) = vbNo Then
  Cancel = True
  Me.Undo
End If
End Sub
hhh1027
Graham,
Thanks a lot
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.