Solved

Validation rules in properties not working as I think they should

Posted on 2015-02-23
3
183 Views
Last Modified: 2015-02-23
I have a control on a form tied to a number field in a table. I am attempting to set a validation rule and validation text which would prevent a record being created without a number in this control. I am using "<>0" for my validation rule, and validation text that says something like "Please enter a quantity before continueing.

I have tried this, as well as "Is Not Null" for a validation rule, and neither one seems to work, as I'm able to breeze right by the quantity control without entering a value with no message or validation occuring.

Is there a better way to make this control a "required" item in my form? My desire is to have the the focus remain on the quantity control until a valid number is input.
0
Comment
Question by:Shooter54
3 Comments
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 250 total points
ID: 40627006
use the before update event of the form
private sub form_beforeUpdate(cancel as integer)

if me.txtQuantity & ""=""  or me.txtquantity = 0 then
   msgbox "Quantity is required"
   Cancel=true
  me.txtQuantity.setFocus
  exit sub
end if

end sub
0
 
LVL 34

Assisted Solution

by:PatHartman
PatHartman earned 250 total points
ID: 40627018
The ONLY event where you can reliably check for "empty" controls is the FORM's BeforeUpdate event.  If the user never places focus in the control in question NO control level event will work because none would ever fire.  Same for the validation rules.  Although the validation rule will pick up the not null condition before the record is saved.  

So, unless you want to put code in EVERY event, you need to content yourself with the code Rey suggested.  All validation code of this type and also any that relies on multiple controls should always be done in the FORM's BeforeUpdate event.
0
 

Author Closing Comment

by:Shooter54
ID: 40627148
Thanks guys.... great advice that worked like a dream.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now