Get the focus back to the same control

odrap

Registered User.
Local time
Today, 10:06
Joined
Dec 16, 2008
Messages
156
In my subform "sfrmorders" , i have a field "Qty" with the default value set to 0. This setting is ment to eliminate the change of a ISNULL or a ISEMPTY. Is that a good technic to obtain that goal?
When entering an orderitem , this control must be assigned a value greater then 0. The possibility exists that the user leaves that control without filling in a value! Yes we have to deal with such a kind of possibilties! So in such a case no "before-update" nor "after_update" takes place.
Therefore i have code in the "lost focus" event of this control to check for a zerovalue. If this is the case, the user get a message and a
"Docmd.Cancelevent" takes place. - Is that neccessary here?-. After that I want the control getting back the focus, so that the user is obliged to input a value greater then zero.
A "Docmd.Gotocontrol me!Qty " don't lead to a succesfull obtaining this goal.
What to do to achieve that goal?
 
I would use the before update event of the form rather than the control.
 
Paul's right on the money! You absolutely cannot use any event of a control (textbox, checkbox, etc) to validate whether a value has been entered or not!

Why? Because the user has the option of simply ignoring the control! If they don't enter the control they won't leave the control, and the LostFocus event won't fire either! They never have to tab/mouse into the textbox[/B]! You can use the BeforeUpdate or AfterUpdate events of a control to validate that data entered is appropriate, or to do something based on what data was entered, but to validate whether or not any data has been entered into the control, you have to use the Form_BeforeUpdate.

As to whether it's better to use zero as the default value and validate whether the control contains a value larger than zero, or to leave it blank and check with IsNull(), I guess it would depend on how mentally challenged your end users are. Most developers check for Null, but I suppose some bozo could enter a zero in the field, an which case IsNull() wouldn't work.
 
Last edited:
I like to thank you very much for the help and the practical advise !!!!
 

Users who are viewing this thread

Back
Top Bottom