bypass the system popup message when data type is wrong

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi all,
in a form I have a textbox which data type is number, integer. If the user
tries to write something different ftom a number, he gets the standard pop up
message 'the value you entered isn't valid for this field', while the msgbox
that I put in the beforeupdate event it is not executed. Here's the code:

----------------- code begins here -----------------
Private Sub medNum_BeforeUpdate(Cancel As Integer)

On Error GoTo Err_medNum_BeforeUpdate

If Not IsNumeric(medNum) Then
MsgBox " The Num field can contain a number between 1 and 400. ",
64, "Wrong data type"
Me!medNum.SetFocus
Cancel = True
End If

Exit_medNum_BeforeUpdate:
Exit Sub

Err_medNum_BeforeUpdate:
MsgBox "errore rilevato: " & Err.Number & ", " & Err.Description
Resume Exit_medNum_BeforeUpdate

End Sub
----------------- code ends here -----------------

is there a way to prevent the standard message to appear, so to give a
chance to my message to appear?

Many thanks
Massimo
 
Max,

See Form Error Event.

That is triggered when that type of error happens so u can then put logic in
there & use "Response = acDataErrContinue"
To not display the default message.

Add this code...

Private Sub Form_Error(DataErr As Integer, Response As Integer)
'Checks for Errors, won't display default Err message,
' keep focus until fixed.

If DataErr = 2113 Then
Beep
MsgBox "Invalid Date", vbCritical, "Invalid Entry"
Response = acDataErrContinue
End If

If DataErr = 2279 Then
' Bad format for Phone #s
Response = acDataErrContinue
End If
End Sub
 
Hi Jeff,

thank you very much for your tip, it has solved this problem 100% (and many
other similar to this).

Massimo
 
Back
Top