Trim a validation rule?

I have a form that has an email field.  I have a validation rule of:

Is Null Or ((Like "*?@?*.?*") And (Not Like "*[ ,;]*"))

to help ensure the email is entered fairly accurately.  For the most part it works great.  However if a user pastes text into the field that has a space at the start of the text the validation rule fails.

Is there a way to incorporate trim into the validation rule or perhaps run after update VBA code to validate the form and trim it instead?
thandelAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

crystal (strive4peace) - Microsoft MVP, AccessRemote Training and ProgrammingCommented:
hi,

a Validation Rule just validates data, it cannot change it.

Normally, one would use a form to enter data, so there could be AfterUpdate event for the control, or BeforeUpdate event for the form, that trims the entry

You could also validate with an event too

have an awesome day,
crystal
0
Gustav BrockCIOCommented:
You can add this code in the OnChange event to clean up the pasted address before it will be evaluated:

Private Sub Email_Change()

    If Asc(Me!Email.Text) = 32 Then
        Me!Email.Text = Trim(Me!Email.Text)
    End If
    
End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Dale FyeOwner, Developing Solutions LLCCommented:
I tend to not use validation rules on fields and use the Form_BeforeUpdate event to test for valid entries in all fields, similar to Crystal's comment above.  I've found that validation rules can be difficult to format properly and get the effect you want, but putting VBA in the Form_BeforeUpdate event allows me to test for all of the required fields, and validation in a single place.  It also allows you to manipulate text (like trimming that leading space).
0
Gustav BrockCIOCommented:
Solution provided.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.