After selection Yes or No goes to next record. That's not what I want...

  • Thread starter Thread starter jennie
  • Start date Start date
J

jennie

Guest
I wrote this code (below)on before update event in all my forms to avoid mistakes by accident. It worked fine but when I select Yes or No access taking me to the next record.
How can I stay in my current record????


Private Sub Form_BeforeUpdate(Cancel As Integer)
On Error GoTo Form_BeforeUpdate_error
Dim intResponse As Integer
Dim strMSG As String
strMSG = "Data on the form has changed. Do you want to save changes?"
intResponse = MsgBox(strMSG, vbQuestion + vbYesNo, "Confirm Action")
Select Case intResponse
Case vbNo
DoCmd.RunCommand acCmdUndo
End Select
Form_BeforeUpdate_exit:
Exit Sub
Form_BeforeUpdate_error:
MsgBox Err & vbCr & Err.Description, vbExclamation, "Form_BeforeUpdate"
Resume Form_BeforeUpdate_exit
End Sub
 
Rather than using the undo - cancel the update with:
cancel = true
 

Users who are viewing this thread

Back
Top Bottom