Trapping Data Validation

  • Thread starter Thread starter Barbara
  • Start date Start date
B

Barbara

If you enter a alpha in a numeric field on a form, Access
gives you the error "The Value You Have Entered Is Not
Valid For This Field". Is there any way to bypass these
error messages and allow the VBA code in the Event
Procedure "Before Update" to catch the error instead?

Thank you for your help
 
Barbara,

I don't believe it is possible to do what you ask. I think the data
type validation will always take place before the Before Update event
kicks in, and I don't think there is any way of changing this. However,
depending on the precise requirements, it would be possible to use the
KeyPress or Change events of the textbox to short-circuit the entry of
invalid data. Here's an example to get you started...

Private Sub TheNumber_Change()
If Me.TheNumber.Text Like "*[a-z]" Then
Me.TheNumber = Null
MsgBox "Oi!"
End If
End Sub
 
Back
Top