Code:
Private Sub Form_BeforeUpdate(Cancel As Integer) 'Provide the user with the option to save/undo
On Error GoTo ErrHandler 'changes made to the record in the form
bWasNewRecord = Me.NewRecord
Call AuditEditBegin("tblParts", "audTmptblParts", "P_ID", Nz(Me.P_ID, 0), bWasNewRecord)
If MsgBox("Changes may have been made to this form or form maybe blank!." _
& vbCrLf & vbCrLf & "Do you want to save these changes?" & vbCrLf & "Can't save Blank form!" _
, vbYesNo, "Changes Made or Blank ...") = vbYes Then
DoCmd.Save
Else
DoCmd.RunCommand acCmdUndo
End If
Exit_ErrHandler:
Exit Sub ' Exit before error handler.
ErrHandler: 'jump to on error.
Call LogError(Err, Error$, "Form_BeforeUpdate_()", P_ID) 'log errors to tLogError table
Resume Exit_ErrHandler
End Sub
I use this Sub in my form.