Validation

  • Thread starter Thread starter Eclipse
  • Start date Start date
E

Eclipse

Guest
How can I set validation for a text field where I restrict the number of characters? For example, if I only want the user to be able to input 12 characters or less, and more than one. >=1 And <=12 would that be correct?
 
validation

You can set validation rules in the text box control when the form is in design view.

Alternatively you can use vb code to check the length of the string either on the onexit event of the text box or the beforeupdate event for the form.

Pesonally I would use the on exit event for the text box as this lets the user know the last action they did was the offending problem. Others may suggest the before update event for the form is the correct method.

The code for the on exit event may look something similar to the following.

If fieldname.length <1 or fieldname.length > 12 then
msgbox " Please make your entry between 1 and 12 characters"
docmd.cancel event
fieldname.setfocus
end sub
end if
' add the rest of the code here you wish to execute if the parameters are correct.

My syntax may be off here and you may need to add a bit to the code but hopefully this should point you in the right direction to get you started.

regards
Ian
 

Users who are viewing this thread

Back
Top Bottom