Before Update save fails

bunji

Registered User.
Local time
Today, 08:30
Joined
Apr 26, 2005
Messages
124
Hi, i am trying to perform a beforeupdate event on a record, but seem to be getting an error.

The undo function works fine but it cannot save, i would be grateful if someone can help as the error is unclear.

Code:

Private Sub Form_BeforeUpdate(Cancel As Integer)

If MsgBox("Are you sure you want save these changes?", vbQuestion + vbYesNo) = vbYes Then
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
Else 'user clicked no
DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70
End If

End Sub



Error that i am getting.....

Run-time error '2115'

The Macro or function set to the beforeUpdate or ValidatationRule propety fot this field is preventing from saving the data in the field.

Thanks
 
The Form_BeforeUpdate event takes place just before the record is saved. If you do nothing, all of the record will be saved. You just need to give the user that last chance to abort the save.
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)

If MsgBox("Are you sure you want save these changes?", vbQuestion + vbYesNo) = vbNo Then
   Me.Undo  '-- Returns all of the controls to their original value
   Cancel = True
Else
   '--- Do Nothing!!
End If

End Sub
 

Users who are viewing this thread

Back
Top Bottom