I'm creating a data entry form with the standard 'OK' and 'Cancel' buttons. 'OK' will simply close the form, capturing the record, but I want 'Cancel' to close the form and not capture the record. However, so far I've only been able to have it close and not capture the last entered field, but the incomplete or unwanted record is still added to the table.
How can I get past this? Is this b/c the records I'm creating have an autonumber field that is being created immediately? I can setup a macro or event to delete the record on exit, but this seems to be the wrong way to go about it, plus I then have delete confirmations appearing and could be misleading or alarming to users.
Here is one approach. The following code should be on the form's Before Update event:
' The Dirty property is True if the record has been changed.
If Me.Dirty Then
' Prompt to confirm the save operation.
If MsgBox("Do you want to save changes?", vbYesNo + vbQuestion, "Save Record") = vbNo Then