Validation Rule does not kick in if user uses tab and no data is entered!

I use personalized validation rules on my forms. However, if a field needs to have data (ie may not be empty nor null) and there is no default value and the user uses TAB to enter the data then the validation rule does not kick in and the form will save an empty field. Is there a way to force a 100% the validation rule even if the user has not entered any data (and just uses the tab key)??

Thank you for any help!
Regards Michael
mpimAsked:
Who is Participating?
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.

Gustav BrockCIOCommented:
Yes, run the validation rule(s) at the BeforeUpdate event of the form, and cancel if validation fails.
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
PatHartmanCommented:
Some validation can be done in the BeforeUpdate event of a control but checking for presence or a relationship with other controls needs to be done in the form's BeforeUpdate event as Gus mentioned.  Rather than have validation all over the place, I tend to put it in just the form's BeforeUpdate event.  That way it is all together and easier to work with.  I only use the control's BeforeUpdate event if I want to provide a validation message as soon as focus leaves the control so for example, if the user enters a value that must be unique, I would check that in the control event so the user doesn't have to fill in the whole form before finding out that the user code already exists.
If Me.SomeField & "" = "" Then
    Msgbox "SomeField is required.", vbONOnly
    Cancel = True
    Me.SomeField.SetFocus
    Exit Sub
End If
If Me.SomeDate < Me.SomeOtherDate Then
    Msgbox "SomeDate must be >= SomeOtherDate", vbOKOnly
    Cancel = True
    Me.SomeDate.SetFocus
    Exit Sub
End If
....

Open in new window

0
Anders Ebro (Microsoft MVP)Microsoft DeveloperCommented:
Furthermore, if you require a field to be non-empty, then at the table level you should specify that the field is Required. That guarantees that the user cannot leave the value blank. It does not provide the most user-friendly message, which is where a before_update check can be useful.
0
Newly released Acronis True Image 2019

In announcing the release of the 15th Anniversary Edition of Acronis True Image 2019, the company revealed that its artificial intelligence-based anti-ransomware technology – stopped more than 200,000 ransomware attacks on 150,000 customers last year.

hnasrCommented:
Try using the control's Exit event.
0
PatHartmanCommented:
And what if the control never gets the focus?  That was a rhetorical question so I'll answer for you.  No control event will ever fire if the control never gets the focus.  That is why it is important to understand form and control events and how to use them.
0
hnasrCommented:
and the user uses TAB to enter the data
Exit event! Try and comment back.
0
mpimAuthor Commented:
Thank you so much for your help!
Regards Michael
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.