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 discarded.
However on my subform, if change is made, I cannot undo that change if the user press the cancel button on the main form.
I am trying to use the same cancel button for both forms, as the main form is a Singleform and the subform a datasheet.
Hope this makes sense!
Antmail
I was stucked with that problem before.
The problem is, you can't!!!!
You can only Undo data that is not yet saved.
as soon as your focus moves to the subform, the information entered
in the main form will be saved automatically, making it impossible to undo anymore.
It will be a long process to make it do what you want.
1. enforce referencial integrity of the main form to the sub form
2. Program the cancel button to delete record in the main form
DoCmd.RunCommand acCmdDeleteRecord
3. Program the main forms BeforeDeleteConfirm to display a message
reminding the user to remove all the items entered in the subfrm
before cancelling the form entry.
This message box would have the a YesNo button.
Yes if the user already removed the items in the subfrm and
No if not yet removed.
4. If user click yes, then the entry will be undone by deleting the record.
If user click no, the message would close and user goes back to the
form to remove the items.
5. To ensure accuracy, that the user really did remove the items before
clicking yes, Access checks the subfrm if it has entries. This is automatic
because you set the referential integrity. Therefore, you cannot delete
a form, if it has related records to its main form.
6. customize the AFterDeleteConfirm to a message box saying "Cancel |
Complete" Then automatically closes the form.
I suppose you know how to do these things. It worked for me.
the only thing is that if you are not using a customized autonumber field,
as you delete that record, the next entry would be the next autonumber field
generated by access.