-1

In the unload event of my Navigation Subform I have the following code.

If MsgBox ("Changes have not been locked and will be lost. Do you wish to  proceed?", vbYesNo) = vbNo Then
    Cancel = True
End If

When the user clicks one of the other navigation buttons on the parent form it presents the Yes/No message box but moves on, closing and clearing the active subform, regardless of what you select. Is it possible to cancel the navigation caused by clicking a navigation button?

Erik A
  • 31,639
  • 12
  • 42
  • 67
Cloude
  • 91
  • 1
  • 2
  • 6
  • Since Access saves a record as soon as you go to another one, I would use the `BeforeUpdate` event rather than an `Unload` event. – iDevlop Jun 09 '16 at 14:43
  • I have a button on my form that saves the record manually via a stored procedure with values from unbound text boxes. The unload event catches the fact that changes haven't been saved and prompts the user. – Cloude Jun 09 '16 at 16:44

1 Answers1

0

Its not clear in what you have outside of your if statement, but seemingly you just have to use the Exit Sub command. This would allow you to completely stop the navigation (if that in itself is a Sub), so:

If MsgBox ("Changes have not been locked and will be lost. Do you wish to proceed?", vbYesNo) = vbNo Then
    Exit Sub
End If
cdomination
  • 605
  • 1
  • 7
  • 25
  • That's all I had in my unload event other than an If statement that checks for unsaved changes (sensitive information involved so I didn't include it). Using Exit Sub in a form_unload event does not cancel it; your form will unload anyways. The reason the cancel is not working in this case is due to it being a subform on a navigation form. I've simply disabled the navigation buttons while there are unsaved changes for now. – Cloude Jun 09 '16 at 16:44