A
Amit
MS Access 2K, Windows XP
=====================
I'm trying to trap the error messages in a form, and replace them with
custom-messages which are less technical. I'm having a problem trying to
figure out how best to do this.
The form is based on a table with three fields, all of which are required,
and one of them is AutoNumber. I have the following code in the "On Error"
event of the form
----------------------------------------------------------------------------------
Private Sub Form_Error(DataErr As Integer, Response As Integer)
' MsgBox "Error#: " & DataErr ' Display the error number
' Response = acDataErrDisplay ' Display Default message
If DataErr = 3314 Then
Response = acDataErrContinue ' Don't display the default message
MsgBox "Enter data in " & Me.ActiveControl.Name
ElseIf DataErr = 2169 Then
Response = acDataErrContinue ' Don't display the default message
MsgBox "Enter data in " & Me.ActiveControl.Name
Else
MsgBox "Error#: " & DataErr
Response = acDataErrDisplay ' Display Default message
End If
End Su
--------------------------------------------------------------------------------
The problem I'm having is in the special case when I delete the data from
the required field and then try to close the form using the "x" in the
right-hand top corner. In that case, I get the error message twice, and then
the form closes. Obviously, I'm not handling the DataErr = 2169 properly.
What I'd like to happen is if someone tries to close the form, s/he gets the
same message and action as for DataErr = 3314.
Would someone have an example of how to handle this error, or maybe point me
in the right direction? It'll be helpful to get an explanation of the
correct logic to be used in this example.
Thanks!
-Amit
PS. I also have code in the Before_Update event of the form to check for the
value, and give an error message if a field is not filled in.
=====================
I'm trying to trap the error messages in a form, and replace them with
custom-messages which are less technical. I'm having a problem trying to
figure out how best to do this.
The form is based on a table with three fields, all of which are required,
and one of them is AutoNumber. I have the following code in the "On Error"
event of the form
----------------------------------------------------------------------------------
Private Sub Form_Error(DataErr As Integer, Response As Integer)
' MsgBox "Error#: " & DataErr ' Display the error number
' Response = acDataErrDisplay ' Display Default message
If DataErr = 3314 Then
Response = acDataErrContinue ' Don't display the default message
MsgBox "Enter data in " & Me.ActiveControl.Name
ElseIf DataErr = 2169 Then
Response = acDataErrContinue ' Don't display the default message
MsgBox "Enter data in " & Me.ActiveControl.Name
Else
MsgBox "Error#: " & DataErr
Response = acDataErrDisplay ' Display Default message
End If
End Su
--------------------------------------------------------------------------------
The problem I'm having is in the special case when I delete the data from
the required field and then try to close the form using the "x" in the
right-hand top corner. In that case, I get the error message twice, and then
the form closes. Obviously, I'm not handling the DataErr = 2169 properly.
What I'd like to happen is if someone tries to close the form, s/he gets the
same message and action as for DataErr = 3314.
Would someone have an example of how to handle this error, or maybe point me
in the right direction? It'll be helpful to get an explanation of the
correct logic to be used in this example.
Thanks!
-Amit
PS. I also have code in the Before_Update event of the form to check for the
value, and give an error message if a field is not filled in.