0
votes

I want to use the ME.UNDO command to prevent changes when closing a form in Access 2013.

I have a form that links to a table which contains a worklist. This form is read-only to prevent accidental changes.

To make changes, the user needs to double-click an item to bring up another form, which is related to this particular work item, then make changes on it.
I have a save button for the user to click to save the changes. If the user just closes this form, I do not want to save the changes.

I am using me.undo in the close event (and this is the only code line in that event). It is still saving the change in the worklist form.

1
plusone for the self-defeating title. If Me.undone Then WoeIsMe - ThunderFrame
You can't use the undo in the close event - that's too late. Take a look at this article: bytes.com/topic/access/answers/… - Wayne G. Dunn

1 Answers

0
votes

If you are only writing a single record, and want to delete that record upon close, then try this. But First, Remove your OnClose event, notice that this fires on the Unload Event of the Form.

Private Sub Form_Unload(Cancel As Integer) 
   On Error Resume Next 
   DoCmd.SetWarnings False
   DoCmd.RunCommand (acCmdUndo)
   DoCmd.SetWarnings True 
End Sub

If the users can create multiple records, then this will only delete the last row inserted.