plz help - Don't want to save a record until button

  • Thread starter Thread starter Mike D
  • Start date Start date
M

Mike D

I have a form set up with an "enter record" button and
a "go back / cancel" button. They work fine until all
fields are filled. When all fields are filled, the
cancel button exits the form, but still saves the record
(and the record saves when filled out without the enter
record button ever being pressed.) Also, when exiting
the database, it saves that way too.

So, I'm basically looking for a way to not save the
record until the "enter record" button is clicked.

I appreciate your help.
 
Access saves the record by default. There are so many ways this can happen,
that the only safe way to catch and block them all is to cancel the
BeforeUpdate event of the form. If you want to destroy what the user was
trying to enter, you should also undo the form.

Private Sub Form_BeforeUpdate(Cancel As Integer)
If MsgBox("Save?", vbYesNo) <> vbYes Then
Cancel = True 'This stops the save.
Me.Undo 'This loses what the user was entering.
End If
End Sub

Private Sub cmdCancel_Click
If Me.Dirty Then
Me.Undo
End If
End Sub
 
Back
Top