Solved

Validation rules in properties not working as I think they should

Posted on 2015-02-23
3
187 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 120

Accepted Solution

by:
Rey Obrero (Capricorn1) 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 36

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 Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Familiarize people with the process of utilizing SQL Server views 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 Access…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

763 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