Validation in Access forms

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

Guest

I am trying to add validation to an e-mail address in a form field, to ensure
it includes the @ symbol. I can program the code in Visual Basic using the
OnExit event, and using the SetFocus function to enable the cursor to return
to the form field. However the Access OnExit event forces the cursor on to
the next field.
I cannot program this validation using a validation rule in the properties.
Is there any better way to program validation so that the cursor is returned
to the same field for the user to enter another input. I also have more
complex pattern matching string validation to do on other form fields by
similar method, so your help is appreciated. Thank you.
 
Try using the BeforeUpdate event. That is always the best place to build
validation because it is easily cancelled, like:

Sub txtEmail_BeforeUpdate ( Cancel as Integer )
Dim varText As Variant

If Not InStr(varText, "@") Then
Msgbox "This is not a valid email", vbOKOnly, "Rejected"
Cancel = True
Exit Sub
End If
End Sub

--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads
http://www.datastrat.com
http://www.mvps.org/access
 
from Rainbow01 Hong Kong

you can use BeforeUpdate event in each field to check the inputed data

"Bridget McWatters" 來函:
 
Back
Top