Custom Error Message

G

Guest

I received an error message that essentially asks you if you want to exit
without saving, YES or Cancel are your options. I customized this message in
vb, but now when my error pops up your only option is to say yes. How can I
keep the Cancel button that was on the original error. Below is my code.

Private Sub Form_Error(DataErr As Integer, Response As Integer)
If DataErr = 3314 Then
Response = acDataErrContinue 'Don't display the default message
MsgBox "Enter data in all required fields."
ElseIf DataErr = 2169 Then
Response = acDataErrContinue 'Don't display the default message
MsgBox "Close form without saving?"
Else
MsgBox "Error#: " & DataErr 'Display the error number
Response = acDataErrDisplay 'Display default message

End If

End Sub

Thanks for any help!
 
G

Guest

Hi Justin,

You need to tell the message box what format you want it to appear in, like
this:

msgbox "something",vbExclamation + vbOKCancel

Hope this helps.

Damian.
 
G

Guest

Thanks Damian! I now get the cancel button on my custom error message, but
when I select cancel it doesn't work. The form still closes no matter if I
select OK or Cancel. Do I need to add code for the cancel button? If vbCancel
= 2 Then or something similar?

thanks!
 

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