Save data verification

  • Thread starter Thread starter Andy Millar
  • Start date Start date
A

Andy Millar

Hi
I'm using the following code (courtesy of this group) to display a
message when closing a form. This allows the user to either continue to
close and save data, close and not save, or go back to the form. It
works OK except when they click cancel. Ideally it should just cancel
the event and take them straight back to the form, but another Access
error message box pops up saying "You can't save this record, an error
has occurred" (the actual message is longer than that). They then have
to choose "no" to go back to the form.
How do I stop that error message coming up?

Here is my code

Select Case MsgBox("Would you like to save your changes?",
vbYesNoCancel + vbQuestion)
Case vbYes
'do nothing
Case vbNo
Me.undo
Case vbCancel
Cancel = True

End Select

Any help much appreciated! - Andrew Millar
 
In what event are you putting that code? Assuming it's in the form's
BeforeUpdate event, in addition to the Me.Undo, put Cancel = True in the
vbNo case.
 
Hi Doug,
yes - its in the Before Update event.
Tried your suggestion, but choosing "cancel" still gives the same
problem
Any other ideas?
Andy


the full error message is:
"You cant save this record at this time
Database name may have encountered an error while trying to save a
record. If you close this object now any changes you made will be lost.
Do you want to close anyway?"
 
here it is:

Private Sub Form_BeforeUpdate(Cancel As Integer)
On Error GoTo Err_Form_BeforeUpdate
Select Case MsgBox("Would you like to save your changes?",
vbYesNoCancel + vbQuestion)
Case vbYes
'do nothing
Case vbNo
Me.undo
Case vbCancel
Cancel = True

End Select
Exit_Form_BeforeUpdate:
Exit Sub

Err_Form_BeforeUpdate:
MsgBox Err.Description
Resume Exit_Form_BeforeUpdate:

End Sub
 

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

Back
Top