Textboxes; forcing format?


Posted by Mandy on August 17, 2001 5:38 AM

I have a user for which has a date entry box

Can I impose a format on this box to only accept dates in the dd-mm-yy format?

If so, how?

Excel 97!

Thank you
Mandy

Posted by Charles on August 17, 2001 6:08 AM


Can't be done!!
C1st

Posted by Damon Ostrander on August 17, 2001 9:19 AM

Hi Mandy,

Charles is correct--the textbox control does not provide built-in support for any kind of input validation. However, it is fairly easy to add such validation yourself with a little VBA code. This is because the TextBox control object has a number of events that enable you to monitor what is being entered by the user and to disallow it if it doesn't meet your format criteria. The events that are useful for this are Change, Enter, and BeforeUpdate. For example, the BeforeUpdate triggers when the user completes his/her data entry into the textbox, and allows you to test the result and cancel (via the Cancel argument) if you so desire. With the Change event you can even monitor the user's every keystroke entry and handle any handle any deviations from your format criteria as they occur.

I hope this helps.

Damon



Posted by Darren on August 17, 2001 3:30 PM

Be less restrictive

Rather than force format entry of a certain type let the user enter it however they want. Do some error checking to determine the value is a date, if it is change it to the format you require, if not a date don't accept the data and ask for re-entry.

Darrren S