![]() |
Validate user input with specific date format
I am new to VBA and not familiar with the syntax. Can someone help me with
the following task? I have user provide me a date using inputbox(), and I want to verify if the input date meets the following requirements. If yes, accept the input. If not, reject the input and loop back to ask for input again. ** Requirements: 1) The input date has to be in mm/dd/yyyy or m/d/yyyy (1/1/2006 for example) format. If user enters single digit for month and day such as 1/1/2006, the script will accept the input and reformat it to mm/dd/yyyy (01/01/20006 for example). 2) The delimiter has to be "/". All other delimiters will be rejected. 3) Reject input if condition 1) and 2) above are not met. Loop back to ask for user input again. Any help is greatly appreciated. Thanks! YH |
Validate user input with specific date format
YH wrote: I am new to VBA and not familiar with the syntax. Can someone help me with the following task? I have user provide me a date using inputbox(), and I want to verify if the input date meets the following requirements. If yes, accept the input. If not, reject the input and loop back to ask for input again. ** Requirements: 1) The input date has to be in mm/dd/yyyy or m/d/yyyy (1/1/2006 for example) format. If user enters single digit for month and day such as 1/1/2006, the script will accept the input and reformat it to mm/dd/yyyy (01/01/20006 for example). 2) The delimiter has to be "/". All other delimiters will be rejected. 3) Reject input if condition 1) and 2) above are not met. Loop back to ask for user input again. Any help is greatly appreciated. Thanks! YH just and idea: rather than user a input box..maybe use the calendar control on a form where the user just clicks on the date..then the date is format correct in the output and it eliminates the need for the error checking. |
Validate user input with specific date format
How do I do calendar control?
Would appreciate if someone can share how to code the error checking per requirements... Thanks, YH "stevebriz" wrote: YH wrote: I am new to VBA and not familiar with the syntax. Can someone help me with the following task? I have user provide me a date using inputbox(), and I want to verify if the input date meets the following requirements. If yes, accept the input. If not, reject the input and loop back to ask for input again. ** Requirements: 1) The input date has to be in mm/dd/yyyy or m/d/yyyy (1/1/2006 for example) format. If user enters single digit for month and day such as 1/1/2006, the script will accept the input and reformat it to mm/dd/yyyy (01/01/20006 for example). 2) The delimiter has to be "/". All other delimiters will be rejected. 3) Reject input if condition 1) and 2) above are not met. Loop back to ask for user input again. Any help is greatly appreciated. Thanks! YH just and idea: rather than user a input box..maybe use the calendar control on a form where the user just clicks on the date..then the date is format correct in the output and it eliminates the need for the error checking. |
Validate user input with specific date format
Ron de Bruin has some tips/links at:
http://www.rondebruin.nl/calendar.htm ps. I don't think you'll be able enforce your rule that data must be entered in mdy order. If the user enters 03/06/2006, your program may not use what the user really intended (June 3, 2006 or March 6, 2006???). You can assume that they did it correct or tell them what date you're going to use (kind of an "Are you sure you want to use March 6, 2006" prompt)--or just use that calendar control and remove all doubt. YH wrote: How do I do calendar control? Would appreciate if someone can share how to code the error checking per requirements... Thanks, YH "stevebriz" wrote: YH wrote: I am new to VBA and not familiar with the syntax. Can someone help me with the following task? I have user provide me a date using inputbox(), and I want to verify if the input date meets the following requirements. If yes, accept the input. If not, reject the input and loop back to ask for input again. ** Requirements: 1) The input date has to be in mm/dd/yyyy or m/d/yyyy (1/1/2006 for example) format. If user enters single digit for month and day such as 1/1/2006, the script will accept the input and reformat it to mm/dd/yyyy (01/01/20006 for example). 2) The delimiter has to be "/". All other delimiters will be rejected. 3) Reject input if condition 1) and 2) above are not met. Loop back to ask for user input again. Any help is greatly appreciated. Thanks! YH just and idea: rather than user a input box..maybe use the calendar control on a form where the user just clicks on the date..then the date is format correct in the output and it eliminates the need for the error checking. -- Dave Peterson |
Validate user input with specific date format
|
All times are GMT +1. The time now is 01:30 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com