Error when cancelling BeforeUpdate event

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
 
R

Rick Brandt

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.
 
G

Guest

Rick:

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

Any other suggestions?

Steve
 
T

Thomas T

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top