Validate user input with specific date format

G

Guest

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
 
S

stevebriz

YH said:
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.
 
G

Guest

How do I do calendar control?

Would appreciate if someone can share how to code the error checking per
requirements...

Thanks,

YH
 
D

Dave Peterson

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top