title: MS Access 2010 - Prompting user to save changes
body: <p>I have developed a form and I would like to prompt the user to save changes before they navigate away from the modified record.</p>
  
  <p>If the user attempts to navigate away, I want a prompt to appear asking if they wish to save changes, upon which they may select "Yes" or "No".</p>
  
  <p>I have been informed that the <code>Before Update</code> event is the one I need to focus on, but I keep receiving the "the expression before update you entered as the event property setting produced the following error" message.</p>
  
  <p>These are the steps I take before reaching the error:</p>
  
  <ol>
  <li>Change view to Form View</li>
  <li>Make a change anywhere in the record via the form</li>
  <li>Attempt to navigate away from form via navi-buttons that I put into my form (which work just fine if no changes are made but which fail to do anything if a single change has been made)</li>
  <li>Nothing happens, so I revert to Design View, to receive the following error notification</li>
  </ol>
  
  <p><img src="https://i.stack.imgur.com/xgbpU.png" alt="Error notification"></p>
  
  <ol start="5">
  <li>I press OK and then receive this message:</li>
  </ol>
  
  <p><img src="https://i.stack.imgur.com/VVWf8.png" alt="Error message 2"></p>
  
  <p>And then I go back to Square One.</p>
  
  <p>Furthermore, any Conditional Formatting has stopped working altogether since this problem has arisen; I do not know for certain if the two are linked, but thought it worth mentioning.</p>
  
  <p>Any ideas how this can be achieved (ideally error-free)?  Unfortunately, I cannot post my system up as it deals with highly confidential data.</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>I have tried a variety of codes which I have modified, all to no avail.  At present, I have removed any such code altogether, but the code I have tried in the past is something to the effect of:</p>
  
  <pre><code>Private Sub Form_BeforeUpdate(Cancel As Integer)
  
  Dim ctl As Control
  
  On Error GoTo Err_BeforeUpdate
  
  If Me.Dirty Then
     If MsgBox("Do you want to save?", vbYesNo + vbQuestion, _
             "Save Record") = vbNo Then
        Me.undo
     End If
  End If
  
  Exit_BeforeUpdate:
     Exit Sub
  
  Err_BeforeUpdate:
     MsgBox Err.Number &amp; " " &amp; Err.Description
     Resume Exit_BeforeUpdate
  End Sub
  </code></pre>