Cancel Order code

buratti

Registered User.
Local time
Today, 16:15
Joined
Jul 8, 2009
Messages
234
I'm trying to create a button that will cancel/erase data entered on a NEW record, and close the form without saving, but only on a new record that has not been finished or closed yet.

Currently I have something that works, but not exactly in the manner explained above...

Private Sub Form_BeforeUpdate()

If Form.Dirty Then
If MsgBoxYesNo(CancelOrderPrompt) Then
Me.Undo
End If
End If


End Sub


That prompts me if I want to save whenever I close the form regardless if it is a new record or existing record that has been changed.

I would only like for it to prompt me if it is a NEW record that has not been saved/closed yet, and ignore existing records that have been modified.
Then I would like to disable the button for all other records that are NOT NEW. Something like... (I would need the correct syntax here)

Private Sub Form_Load()
If "current record is not new" Then

Me.cmdCancelOrder.Enabled = False
End If
End Sub


Any help would be much appreciated!
 
Thanks!!! So it kinda works, but only if I put it in the BeforeUpdate event of the form and with nothing else. That also makes it prompt me after every way I navigate away from the new record, even if I intend to save it. I need it to work only when I click the Cancel button. If I click close (X), or next record, or anything else other than Cancel that navigates me away from the current record, I want it to save without any prompt. But if I click Cancel, then prompt if I'm sure I want to cancel, and if yes, then Me.undo, or whatever else works there. The code that is in BeforeUpdate now (that works) is:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.NewRecord Then
If MsgBoxYesNo(CancelOrderPrompt) Then
Me.Undo
End If
End If
End Sub
 
Last edited:

Users who are viewing this thread

Back
Top Bottom