Input Validation

nir

New member
Local time
Today, 08:06
Joined
Oct 27, 2005
Messages
5
I wish to validate field value on a form before leaving to the next control, and remain in the control until input is validated.

Help on this will be highly appreciated.
 
Last edited:
onexit code...

(assume field name is tmpField1)

if TmpField1<> 9 then cancel = true

Only if the data entered is 9 will it move to the next field!!
(You will also need to supply a way of gettin out

e.g. if TmpField1 = "Exit" then TmpField2.setfocus : Exit Sub
 
You need to use the BeforeUpdate event of the control and cancel the event if the validation test is true. The user will not be able to move to another control if you correctly code the event for your test.

Search around for the key word BeforeUpdate and you will find plenty of examples.
 
The problem with this approach is that if a user doesn't tab into the control the event will not fire, for absolute certainty you should use the BeforeUpdate event of the Form
 
Don't forget that you may have to validate for whether the dat is numeric or alpha. The ISNUMERIC code is useful. Do you also have to validate for the length of the input. Lots to consider if you want a really robust check.
 
I cooked up a sample that deals with confirming edits to fields (i.e. controls) and records on a form. If would be easy to add data validation to it once you understand using the BeforeUpdate events (Form and Control).

See the article here. A link to the sample file can be found at the end.
 

Users who are viewing this thread

Back
Top Bottom