On Form Error: MsgBox

I

Iram

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
 
P

PJFry

You can remove the close button and avoid the issue. On the Property Sheet
for the Form change the the Close Button to No.
 
I

Iram

I would like to do that however if they close the database program (and not
just the form) I want it to prompt the first prompt in the code below then
say No to the error in question below and have them pushed back to the data
entry form...
 
D

DStegon via AccessMonster.com

you can tell the msgbox box what buttons to present and which ones you want
to make default. The code below make the NO button have the Focus.

MsgBox "This is your text", vbYesNo + vbDefaultButton2, "This is your title"

MsgBox "this has three buttons", vbYesNoCancel + vbDefaultButton3 +
vbCritical, "AND THIS also Displays the CRITICAL icon" ' setting the focus on
the cancel button

MsgBox "this has three buttons", vbYesNoCancel + vbDefaultButton1
+vbInformation, "AND THIS also Displays the ""I"" (information) icon" ' also
sets focus on the Yes Button
I would like to do that however if they close the database program (and not
just the form) I want it to prompt the first prompt in the code below then
say No to the error in question below and have them pushed back to the data
entry form...
You can remove the close button and avoid the issue. On the Property Sheet
for the Form change the the Close Button to No.
[quoted text clipped - 39 lines]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top