Solved

Validation rules in properties not working as I think they should

Posted on 2015-02-23
3
186 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 35

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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
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…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

856 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