Solved Stuck with "the value you entered isn't valid for this field"

Romio_1968

Member
Local time
Today, 19:37
Joined
Jan 11, 2023
Messages
126
I have an unbound textbox, with format set to 'General Number', no decimals.
When a non numerical key is entered, the default error message pops up: "the value you entered isn't valid for this field"
1676295832251.png


To prohibit user for entering such values, i set an On Change event for the control
Code:
Private Sub PrintYearStart_Change()

  If Not IsNumeric(Me.PrintYearStart.Value) Then
    MsgBox "Valoare incorecta!" & vbNewLine & vbNewLine & _
           "Anul este un numar format din 4 cifre" & vbNewLine & _
           "(Exemplu: 1968)", vbExclamation, "Atentie"
    Me.PrintYearStart.Value = MinPrintYear
  End If
 
End Sub
Instead of executing the MsgBox and do the roll back, the default Access error message pops up, and no rollback is executed, but a Cancel seems to be done (the non numerical value stays, highlighted)

What am I doing wrong?

RESOLUTION
___________________________________________________________________
Instead of testing Me.PrintYearStart.Value, i chaned it to Me.PrintYearStart.Text
The custom behavior is now triggered

(thank you, arnelgp)
 
Last edited:
use BeforeUpdate event to validate.
both you can't assign any value on that event except to Undo it.
 
use BeforeUpdate event to validate.
both you can't assign any value on that event except to Undo it.
Tried... no change
The very first key is entered, the default error handler is triggered and any other action is canceled.
On form level is not set an errorhandler
 
PrintYearStart
this textbox does not have (or still has the original value) on the Change event.
you should check it's .Text property and not it's .Value.
 
You could also respond to the form error.
Code:
Private Sub Form_Error(DataErr As Integer, Response As Integer)
    If DataErr = 2113 Then 'please check error number
        with Me.ActiveControl
            if .Name = "PrintYearStart" Then
                msgbox "your message"
                .Undo
                Response = acDataErrContinue
            end if
        End with
    End If
End Sub
 
Tried... no change
The very first key is entered, the default error handler is triggered and any other action is canceled.
On form level is not set an errorhandler
Yes... that was it.
Checked for Me.Control.Textx and the custom behavior comes up.
Thank You
 
1. The change event runs once for EACH character typed. You have to check specifically for 0-9 to limit to numeric characters.
2. The IsNumeric() function allows non-numeric characters because it supports scientific notation.
 

Users who are viewing this thread

Back
Top Bottom