validation of text


Posted by andy on December 14, 2001 4:20 AM

My students are required to design an application to record details of hospital equipment loans. I have created the applicatiom myself (so i know how to!) and am now fine tuning aspects of it.

Part of the application brings up a user form which has text boxes for the user to enter details of name address etc. this information is then transferred to the spreadsheet creating a list (like a database).

What I want to do now is validate the information as it goes into the textboxes (or at the end) so that for example you cannot enter text in the telephone number box.

I'm guessing I need to dim the variables as type (integer, string etc) but when I do and the wrong info goes in the application crashes.

Adding on 'error resume next' just fills in stuff like numbers with a 0 if you leave them blank.

Any clues please - I want an error message to appear telling them where they have made the mistake.

I can provide current code if I have not made this clear.

Andy



Posted by Mike C on December 14, 2001 5:22 AM

imho, you should provide for validation in the form's event procedures so that the data you manipulate are known to be valid before putting them into the spreadsheet.

If you want to stick with the basic set of controls that come standard, this will mean create event procedures for each control (in particular the BeforeUpdate event). This will prevent the user from exiting the form field if the data it contains is not valid. If your validations are simple, this should be a relatively easy thing to do.

You can also take advantage of a number of freely available activeX controls available on the net (search for "free ocx text box"). There are text box controls that provide automatic validations via the properties windows.