suppress field error message

patkeaveney

Registered User.
Local time
Today, 09:55
Joined
Oct 12, 2005
Messages
75
Hi all

I have a numeric field on a form and want to stop the user from entering non numeric data.

If the user enters non numeric data the Access error message
"the value you entered isn't valid for the field".

I want to suppress this error message and replace it with my own.

Where do I need to place my code to achieve this?
What is the error code generated by this message?

Thanks in advance

Pat
 
Something like this:
Code:
Private Sub Form_Error(DataErr As Integer, Response As Integer)
Dim Message As String
 If DataErr = 2113 Then 'Value entered is invalid
  Message = "You Must Enter a Numeric Value for the Field:  " & Me.ActiveControl.Name
  Response = MsgBox(Message, vbExclamation, "Data For This Field is Not Valid/Complete")
  Response = acDataErrContinue
 End If
End Sub
 
Thank you missingling

I was checking the Err flag not the DataErr.

Works a treat now

Thanks for your speedy response
 
I never noticed the Form_Error event.
Thanks missinglinq for pointing this out.

Now, I can allow my users to type equations and fractions into numeric fields!

Code:
Private Sub Form_Error(DataErr As Integer, Response As Integer)
    On Error GoTo ErrLog
 
    'Allow Formulas to be entered into Numeric Fields
    If DataErr = 2113 Then 'Invalid Entry Error
        If Left(ActiveControl.Name, 6) = "Number" Then
            Response = acDataErrContinue
            If CanEval(ActiveControl.Text) Then
                ActiveControl.Text = Eval(ActiveControl.Text)
            Else
                CustomMsgBox "You have entered invalid text in a numeric field.", _
                  "You may enter a valid number, equation or fraction.", _
                  vbExclamation, "Database Manager"
            End If
        End If
    End If
 
    Exit Sub
ErrLog:
    If Err.Number = 2115 Then Resume Next 'Can't Save Record at this time error
    Call ErrorLog(Err.Number, Err.Description, "Form_frmItem.Form_Error")
    Resume Next
End Sub

(CanEval, CustomMsgBox and ErrorLog are custom functions).

Evan
 
Hi there. I was searching for a solution to the custom error probelm. This is close, but there's something else that would be useful.

I'd like to customise the message according to which object on the form generated the problem; so if it's txtDateEntered we get "dd/mm/yyy required in this field" and if it's txtNumber we get "numeric values required in this field".

Basically, can I determine which object generated the error?

thanks in advance! dave
 
I used this:

Screen.ActiveControl.Name

Seems to work ok!
 

Users who are viewing this thread

Back
Top Bottom