Trapping Data Validation

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
 
S

Steve Schapel

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top