Solved

Validation rules in properties not working as I think they should

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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how to not remove leading zeros 9 38
View vs Edit mode enhancements 12 40
How can I create a table in a linked database, in VB? 7 17
DBF to ... Converter 5 38
In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

911 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

17 Experts available now in Live!

Get 1:1 Help Now