Validation error on undo command?

Johnny

Registered User.
Local time
Today, 13:11
Joined
Mar 27, 2011
Messages
39
I have this running in the before update event of a field on a subform

Code:
Private Sub idEmpTbl_BeforeUpdate(Cancel As Integer)
Dim strMsg As String
Dim iResponse As Integer
' specify the message to display
strMsg = "Do you wish to save the changes?" & Chr(10)
strMsg = strMsg & "Click Yes to Save or No to Discard changes."
' display the message box
iResponse = MsgBox(strMsg, vbQuestion + vbYesNo, "Save Record?")
' check user's response
If iResponse = vbNo Then
    'undo the change
    DoCmd.RunCommand acCmdUndo
    'Cancel the update.
    Cancel = True
   End If
End Sub

I am trying to stop a user from entering data then trying to close the form without actually saving the record. The problem is when they click NO and it runs the undo command it gives me an error saying "This Value violates the validation rule for the field or record".

I dont have a validation on this field or the record, I had an input mask which I removed and still getting the error. The field in question is actually the FK record on a junction table but duplicates are okay since the PK for the junction table is unique.

Is there a problem with the code? If not any other ideas?

(posted db, form in question is DateMain form, PSN Entry field, it's 2007 sorry!)
 

Attachments

Just guessing here, but have you tried me.undo instead of the runcommand action?
 
For starters, if your intent is to save or dump the record/changes, the code belongs in the Form_BeforeUpdate event, not the BeforeUpdate event of a Control.

Linq ;0)>
 
For starters, if your intent is to save or dump the record/changes, the code belongs in the Form_BeforeUpdate event, not the BeforeUpdate event of a Control.

Linq ;0)>


That was it, thank you!
 
As in real-estate, the first, second and third most important thing about code is 'location, location, location!' :D

Glad we could help!

Linq ;0)>
 

Users who are viewing this thread

Back
Top Bottom