Validation in Access forms

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.
 
A

Arvin Meyer [MVP]

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
 
G

Guest

from Rainbow01 Hong Kong

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

"Bridget McWatters" 來函:
 

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