Error when cancelling BeforeUpdate event

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I give the user the option to NOT save a new record if they've changed their
mind by using the following code in the BeforeUpdate event of the form:
If Me.NewRecord Then
If MsgBox("Do you want to save this new document?", vbYesNo) = vbNo Then
Cancel = True
MsgBox "Update was cancelled", vbOKOnly
End If
End If

So, if the user begins to fill in a new form, changes their mind and closes
the form, they will be questioned and can hit NO. However, when they hit NO,
an error message comes up that says:
You can't save this record at this time!
Registrations may have encountered an error while trying to save a record.
If you close this object now, the data changes you made will be lost.
Do you want to close the database object anyway?
YES / NO

How do I keep this error message from coming up?

Thanks

Steve
 
Steve said:
I give the user the option to NOT save a new record if they've
changed their mind by using the following code in the BeforeUpdate
event of the form: If Me.NewRecord Then
If MsgBox("Do you want to save this new document?", vbYesNo) =
vbNo Then Cancel = True
MsgBox "Update was cancelled", vbOKOnly
End If
End If

So, if the user begins to fill in a new form, changes their mind and
closes the form, they will be questioned and can hit NO. However,
when they hit NO, an error message comes up that says:
You can't save this record at this time!
Registrations may have encountered an error while trying to save a
record. If you close this object now, the data changes you made will
be lost.
Do you want to close the database object anyway?
YES / NO

How do I keep this error message from coming up?

Try adding...

Me.Undo

....after the Cancel = True line.
 
Rick:

Thanks for the reply. Unfortunately, it still does the same.

Any other suggestions?

Steve
 
Hmmm...

i'm not an expert, but try putting the code in the afterUpdate event and
replace the Cancel=True line by the previous mentioned undo statement.
 
Back
Top