On Form Error: MsgBox



Hello,
I am using Access 2003 and I have the below code to provide a msgbox to the
user when they try to click on the small x at the top right hand corner of
the screen to exit the form. This code works swell however after they click
Ok to this message they get a "You can't save this record at this time ...If
you close the object now, the data changes you made will be lost. Do you want
to close the database object anyway? Yes or No".

I want to add code to the below code to automatically select "No" on this
error msg. If the user accidentally clicks Yes they loose all of their data.
Can you help me modify the below code to prevent the above error message from
coming up(this code is located in the forms code not in a module)?

Private Sub Form_Error(DataErr As Integer, Response As Integer)

'If an error occurs because of missing data in a required field
'display our own custom error message

Const conErrRequiredData = 3314

If DataErr = conErrRequiredData Then
MsgBox ("Orange fields are required in order to save your data.
Choose No on the next screen to continue adding information to this case.")
Response = acDataErrContinue
Else
'Display a standard error message
Response = acDataErrDisplay
End If

End Sub


I know that this code below helps pull the error code however I just can't
get it to work...

Private Sub Form_Error(DataErr As Integer, Response As Integer)
Debug.Print "DataErr = "; DataErr
End Sub


Your help is greatly appreciated!
Iram
.