Disallow using red X to close Access from form
Posted on 2014-02-07
What I want is if the red X in the far upper right corner is pressed, the user is presented the message "You must use one of the Close buttons..." and returned to the form. Here is the code:
Private Sub Form_BeforeUpdate(cancel As Integer)
If MsgBox("You must use one of the Close buttons...", vbOKOnly) = vbOK Then
cancel = True
Problem 1: If no change has been made on the form, this event is ignored. Access is closed.
Problem 2: If a change has been made, the "You must use one of the Close buttons..." is displayed, but it is immediately followed by an Access message:
You can't save this record at this time. Do you want to close the database object anyway? Yes. No.
Again, I want to force the user to use one of the Close buttons on the form.