Message Box Question

T

tina

-----Original Message-----
I have a form that may be closed without the primary
index value being entered. When this happens an error
message is displayed. I would like to override that
error message with one of my own. I also want to be able
to close the form without further error messages (also
not save the current record) by having the user to select
<Cancel> on my own Message Box. Can someone help me?

Don Rountree
.
one option is to add a procedure to the form's OnError
event, as

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

Dim intChoice As Integer

If DataErr = 3058 Then
Response = acDataErrContinue
intChoice = MsgBox("Put your custom message here."
& vbCr & vbCr & "Click OK to add the " _
& "missing information." & vbCr & "Click
Cancel to close the window without saving the " _
& "record.", vbOKCancel + vbDefaultButton2)
If intChoice = vbCancel Then
Me.Undo
DoCmd.Close , , acSaveNo
End If
End If

End Sub

fyi, you can initially trap form (record) errors here too,
so you can identify the error number, as

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

MsgBox DataErr

End Sub
 

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