Beforeupdate Procedure

  • Thread starter Thread starter Adam
  • Start date Start date
A

Adam

When I use this code in the before update event procedure

Private Sub Form_Before(Cancel As Integer)
Cancel = True
Me.Undo
MsgBox "Your changes were cancelled"
End Sub

it won't allow any date to be entered.

What I want to happen is when a form is closed the data not to be saved
unless I click an enter button to save the data. Once the data is saved the
form can be closed
 
Adam said:
When I use this code in the before update event procedure

Private Sub Form_BeforeUpdate(Cancel As Integer)
Cancel = True
Me.Undo
MsgBox "Your changes were cancelled"
End Sub

it won't allow any date to be entered.

"Of course not!" Your code always executes. No test, no consideration:
Cancel!
What I want to happen is when a form is closed the data not to be saved
unless I click an enter button to save the data. Once the data is saved the
form can be closed

Before implementing this, ask yourself if that is good interface design.
I'd say it is not: when the user closes the form with unsaved data, your
application should present a dialog box with a warning message, and
options to save, discard, or not close the form.

This having said... You can catch a closing form with the Unload event
(that one has a Cancel parameter). You can check the Dirty property of
the form (spelled Me.Dirty) if data was entered, but not saved.

Is that enough information?
 
Back
Top